@name Helicopter
@inputs P:wirelink Rotor:entity Swivel:entity
@outputs Float Pitch
@persist TargetAngle:angle Ang:angle  
@trigger 

interval(1)
if(first()){
    Float = 200
}

Active = P["Active",number]
W = P["W",number]
A = P["A",number]
S = P["S",number]
D = P["D",number]
Shift = P["Shift",number]
Space = P["Space",number]
Alt = P["Alt",number]

E = entity():isWeldedTo()
if(Active){
E:applyForce((-E:vel()*E:mass()*vec(1,1,10)/5+vec(0,0,9)*E:mass()))
E:applyAngForce(-E:angVel()*E:mass()*5)
E:applyForce(E:up()*Float*E:mass())
E:applyForce(-vec(0,0,500)*E:mass())
}
E:applyAngForce(Ang*ang(0.5,1,1)*E:mass()*1)

Ang=TargetAngle-E:angles()
TargetAngle = ang(0,E:angles():yaw(),0)

if(W & Pitch > -2500){
    Pitch -= 5
}
if(S & Pitch < 2500){
    Pitch += 5
}
if(!W & !S & Pitch > 0){
    Pitch -= 25
}
if(!W & !S & Pitch < 0){
    Pitch += 25
}
E:applyAngForce(ang(0,0,Pitch)*E:mass())
if(A){
    E:applyAngForce(ang(-80,250,0)*E:mass())
    Swivel:applyAngForce(ang(0,0,1000)*Swivel:mass())
}
if(D){
    E:applyAngForce(ang(80,-250,0)*E:mass())
    Swivel:applyAngForce(ang(0,0,-1000)*Swivel:mass())
}
if(Space & Float < 800){
    Float+= 2
}
if(Alt & Float > 100){
    Float-= 2
}
if(!Space & !Alt & Float < 500){
    Float+=10
}
if(!Space & !Alt & Float > 500){
    Float-=10
}
if(Active){
    Rotor:applyAngForce(ang(0,0,Float^1.6)*Rotor:mass())
}
