@name Make It Fly
@inputs [AdvPod Numpad]:wirelink #Gun:wirelink 
@outputs 
@persist 
@trigger 
@model models/props_junk/PopCan01a.mdl

runOnTick(1)

Fly=1
Ranger=1


O=owner()
G=entity():isConstrainedTo()
if(Ranger){
    rangerFilter(G)
    Aim=rangerOffset(10000,O:pos(),O:eye()):position()
}else{
    Aim=O:aimPos()
}
if(->AdvPod&AdvPod["Active",number]){
    Aim=AdvPod["AimPos",vector]
}

if(!G&dupefinished()){selfDestruct()}
#G=Gun:entity()
Dir = G:pos()-(Aim)
#Q = quat(Dir:toAngle())*qRotation(vec(0,0,1),0) #-X
#Q = quat(Dir:toAngle())*qRotation(vec(0,0,1),180) #X
Q = quat(Dir:toAngle())*qRotation(vec(0,1,0),90) #-Z
#Q = quat(Dir:toAngle())*qRotation(vec(0,1,0),-90) #Z
#Q = quat(Dir:toAngle())*qRotation(vec(0,0,1),90) #Y
#Q = quat(Dir:toAngle())*qRotation(vec(0,0,1),-90) #-Y
G:applyTorque((150*G:toLocal(rotationVector(Q/quat(G))+G:pos()) - 12*G:angVelVector())*G:inertia())


if(Fly){
    XYZ=O:aimPos()
    Speed=100*(G:mass()/4)
    G:applyForce(Speed*(XYZ-G:pos())-(G:vel()/2)*G:mass())
}
