@name Plane Base
@inputs [Pod EGP]:wirelink Seat:entity 
@outputs 
@persist Height Yaw 
@trigger 
runOnTick(1)

E = entity():isWeldedTo()
Speed = round(toUnit("mph",E:vel():length()))

EGP:egpText(1,""+Speed,vec2(256,456))

if (first()) {
    holoCreate(0)
    holoCreate(1)
    holoCreate(2)
    
    rangerPersist(1)
    rangerFilter(E)
    rangerFilter(Seat)
    rangerFilter(players())
    
    Height = 40
    
    E:setMass(50000)
    
    EGP:egpClear()
    EGP:egpAlign(1,1,1)
}

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 Shift = Driver:keySprint()
local Space = Driver:keyJump()
local Active = Driver:isValid()

R = rangerOffset(Height+10,E:toWorld(vec(80,0,0)),-E:up())
R2 = rangerOffset(Height+10,E:toWorld(vec(-80,0,0)),-E:up())
R3 = rangerOffset(Height+10,E:toWorld(vec(0,-140,0)),-E:up())

RD = R:distance()
R2D = R2:distance()
R3D = R3:distance()

Added = (RD+R2D+R3D)/3

if (Speed >= 25) {
    Ranger = rangerOffset(32768,Seat:pos(),Seat:toLocalAxis(Driver:eye()))
    Yaw = (Ranger:pos() - E:pos()):toAngle():yaw()
}

if (Added < Height) {
    Diff = Height - Added
    Angle = ang((RD+R2D)-(R2D+RD),Yaw,(R2D+RD)-(RD+R2D))
    
    E:applyForce((vec(0,0,Diff * 8) - E:vel()) * E:mass() + E:right() * (S-W) * E:mass() * 150 * (3 + Shift))
    E:applyAngForce((E:toLocal(Angle)*200 - E:angVel()*20) * shiftL(ang(E:inertia())))
}

holoPos(0,R:pos())
holoPos(1,R2:pos())
holoPos(2,R3:pos())
