@name Mounted Gun
@inputs Gun:wirelink
@outputs 
@persist 
@trigger

#By Captain Maim STEAM_0:1:8017844
 
O=owner()
G=Gun:entity()
runOnTick(1)
Fire=0
Play=players()

for(C=1,Play:count()){
    if(Play[C,entity]:pos():distance(entity():pos())<150){
        Fire=Play[C,entity]:keyUse()
    rangerFilter(G)
    Range=1000
    #Aim=rangerOffset(Range,G:pos(),Play[C,entity]:eye()):pos()
    
    Aim=Play[C,entity]:aimPos()   
        break
    }
}
if(first()){holoCreate(1,Aim,vec(1,1,1)*0.25,ang(),vec(255,0,0))}
holoPos(1,Aim)
#G=entity():isConstrainedTo()
if(Fire){Gun["Fire",number]=1}else{Gun["Fire",number]=0}

Dir = G:pos()-(Aim)
Q = quat(Dir:toAngle())*qRotation(vec(0,0,1),180)
G:applyTorque((150*G:toLocal(rotationVector(Q/quat(G))+G:pos()) - 12*G:angVelVector())*G:inertia())

Speed=50
XYZ=entity():pos()+vec(0,0,50)
G:applyForce(Speed*(XYZ-G:pos())-(G:vel()/2)*G:mass())
