@name Hover Tank
@inputs [Pod EGP]: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 Shift = Driver:keySprint()
local Active = Driver:isPlayer()
local M1 = Driver:keyAttack1()
local M2 = Driver:keyAttack2()

if (first() | dupefinished()) {
    E:setMass(50000)
    
    Height = 35
}

if (Active == 1) {
    Height = 35
    
    ScreenRes = egpScrSize(Seat:driver())
    Res = ScreenRes/2
    
    EGP:egpPoly(4,Res,Res + vec2(24,17),Res + vec2(20,17),Res + vec2(0,4),Res + vec2(-20,17),Res + vec2(-24,17))
    EGP:egpColor(4,vec(255,0,0))
}

if (M2) {EGP:egpColor(4,vec(0,255,0))}

if (Active == 0) {
    Height = 10
    EGP:egpClear()
}

if (A) {Yaw = 2}
if (D) {Yaw = -2}
if (!A & !D) {Yaw = 0}

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

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*(Shift+1)*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))
