@name Airplane
@inputs PY:vector2 RLeft RRight Faster Slower Break Active
@outputs XYZ:vector
#@outputs Ang:angle Pitch Roll Local:angle Ang1:angle AngDist:angle
@persist P Y R Speed
@trigger 
Self=entity():isConstrainedTo()
if(!Self){Self=entity()}
#runOnTick(1)
P=PY:x()
R=PY:y()
Y=(RLeft-RRight)*5
Time=50/1000
interval(Time*1000)
InertiaConstant = 27.05307927383

Ang=Self:angles()

TargetAng=angnorm(ang(P,Y,R))
Local=Self:toLocal(Self:angles())
Ang1=angnorm(Ang)

AngDist=TargetAng-Local
#AngDist=TargetAng-Self:angles()
#    AttackPosition=owner():aimPos() #aim here
#
#    AttackPosition=vec((cos(P)+sin(P)+90),sin(Y)*Rad,sin(R)*Rad)+Self:pos()
#    RelativePosition = Self:toLocal(AttackPosition-(Self:massCenter()-Self:pos()))
#    AngDist = angnorm(RelativePosition:toAngle():setRoll( -Self:angles():roll()))
Inertia = InertiaConstant*ang(Self:inertia():y(),Self:inertia():z(),Self:inertia():x())
AngVel = AngDist/Time
Self:applyAngForce(Inertia*(AngVel-Self:angVel()))

   #This is move to vector code 
#runOnTick(1)

#T=0.015
Range=1000
Speed+=(Faster-Slower)*50
Speed=clamp(Speed,-Range,Range)
if(Break|!Active){Speed=0}
S=vec(Speed,Speed,Speed)
XYZ=Self:angles():right()*200+Self:pos()
if(first()|duped()){
    holoCreate(1,XYZ,vec(0.5,0.5,0.5))
    holoParent(1,Self)
}

holoPos(1,XYZ)

Dist=XYZ-Self:pos()
Vel=clamp(Dist/Time,-S,S)
Self:applyForce(Self:mass()*(Vel-Self:vel()))
#
#Time=100/1000
#interval(Time*1000)
#O=owner()
#Detonate=O:keyUse()
#E=entity():isConstrainedTo()
#Speed=400
#S=vec(Speed,Speed,0)
#XYZ=O:aimPos()
##E:applyForce(Speed*(XYZ-(E:pos()-vec(0,0,E:pos():z())))-E:vel()*E:mass())
#
#Vel=clamp((XYZ-E:pos())/Time,-S,S)
#E:applyForce(E:mass()*(Vel-E:vel())*vec(1,1,0))
