@name VTOLY
@inputs Pod:wirelink 
@outputs 
@persist Height:number Yaw 
@trigger 
runOnTick(1)

E = entity():isWeldedTo()

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local W = Driver:keyForward()
local A = Driver:keyLeft()
local S = Driver:keyBack()
local D = Driver:keyRight()
local Space = Driver:keyJump()
local Shift = Driver:keySprint()
local Active = Driver:isPlayer()
local M1 = Driver:keyAttack1()
local M2 = Driver:keyAttack2()

if (first() | dupefinished()) {
    E:setMass(251)
}

if (Active == 0) {
    Height = 40
}

if (A) {Yaw = 2}
if (D) {Yaw = -2}
if (!A & !D) {Yaw = 0}
if (Space) {Height++}
if (Shift) {Height--}

rangerFilter(E) 
Rng = rangerOffset(E:pos(),E:pos()-vec(0,0,99999))

if (Rng:hit()) {
    Diff = Height-Rng:distance()

    E:applyForce(vec(0,0,Diff)*2*E:mass()-(E:vel())*E:mass()+E:forward()*(S-W)*180*E:mass()+E:up()*E:mass())
}

function entity:turnTo(Tarang:angle) {
    local V = This:toLocal(rotationVector(quat(Tarang)/quat(This))+This:pos())
    This:applyTorque((1000*V - 30*This:angVelVector())*This:inertia()/3)
}

E:turnTo(E:angles():setPitch(0):setRoll(0):setYaw(E:angles():yaw()+Yaw))
