@name Mech Floaty
@inputs Pod:wirelink 
@outputs Alti Hover
@persist Pos:vector Ang:angle Yaw Yaw2 Yaw3 
interval(16)

E = entity():isWeldedTo()
PITCH = E:vel():length()/25

Speed = 6
UpDown = 3
TurnSpeed = 2
Height = 50

Alti = rangerOffset(50000,Pos + entity():up()*-20, vec(0,0,-1)):distance()
if (Alti < 34) {Hover = 1} else {Hover = 0}

if (first() | dupefinished()) {
    E:setMass(50000)
    
    Pos = entity():isWeldedTo():pos()
    Ang = entity():isWeldedTo():angles()
    
    function number swivel(A:number,B:number) {
        local C1=(B+(360-A))%360
        local C2=C1-360
        return abs(C1)<abs(C2) ? C1 : C2
    }
    
    function angle swivel(A:angle,B:angle) {
        return ang(
            swivel(A:pitch(),B:pitch()),
            swivel(A:yaw(),B:yaw()),
            swivel(A:roll(),B:roll())
        )
    }
    
    function number entity:rotat(Ang:angle,Speed:normal) {
        This:applyAngForce((swivel(This:angles(),Ang) - This:angVel()) * This:mass())
        return 1
    }
    
    function number entity:rotat(Ang:angle) {
        This:rotat(Ang,1)
        return 1
    }
    
    function number entity:move(Vec:vector,Speed:normal) {
        This:applyForce(((Vec-This:pos())-This:vel())*This:mass()*Speed)
        return 1
    }
    
    function number entity:move(Vec:vector) {
        This:move(Vec,1)
        return 1
    }
    
    function number entity:moveNoReset(Vec:vector,Speed:normal,Slowdown:normal) {
        This:applyForce(((Vec-This:pos()-This:vel()*Slowdown))*This:mass()*Speed)
        return 1
    }
    
    holoCreate(1)
    holoPos(1,E:toWorld(vec(0,40,20)))
    holoAng(1,E:toWorld(ang(0,0,0)))
    holoScale(1,vec(0.5,0.5,0.5))
    holoParent(1,E)
    
    holoCreate(2)
    holoPos(2,E:toWorld(vec(0,-40,20)))
    holoAng(2,E:toWorld(ang(0,0,0)))
    holoScale(2,vec(0.5,0.5,0.5))
    holoParent(2,E)
    
    holoCreate(3)
    holoModel(3,"models/props_combine/headcrabcannister01a.mdl")
    holoPos(3,E:toWorld(vec(0,40,20)))
    holoAng(3,E:toWorld(ang(-90,0,0)))
    holoScale(3,vec(0.6,0.7,0.7))
    holoParent(3,1)
    
    holoCreate(4)
    holoModel(4,"models/props_combine/headcrabcannister01a.mdl")
    holoPos(4,E:toWorld(vec(0,-40,20)))
    holoAng(4,E:toWorld(ang(-90,0,0)))
    holoScale(4,vec(0.6,0.7,0.7))
    holoParent(4,2)
    
    for (Al = 1,2) {holoAlpha(Al,100)}
}

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local Active = Driver:isPlayer()
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 M1 = Driver:keyAttack1()
local M2 = Driver:keyAttack2()

Yaw += clamp((A - D)*20 - Yaw,-4,4)
Yaw2 += clamp((W - S)*25 - Yaw2,-10,10)
Yaw3 += clamp((M1 - M2)*20 - Yaw3,-2,2)

holoAng(1,holoEntity(1):parent():toWorld(ang(Yaw2-Yaw,0,-Yaw3)))
holoAng(2,holoEntity(2):parent():toWorld(ang(Yaw2+Yaw,0,-Yaw3)))

if (Active) {
    Pos+=
    (
        (W ? E:forward() : vec()) +
        (S ? E:forward()*-1 : vec()) +
        (M1 ? E:right()*-1 : vec()) +
        (M2 ? E:right() : vec())
    ) * Speed
    
    Pos+=
    (
        (Space+Hover ? E:up() : vec()) +
        (Shift ? E:up()*-1 : vec())
    ) * UpDown
    
    Ang+=
    (
        (A ? ang(0,1,0) : ang()) +
        (D ? ang(0,1,0)*-1  : ang())
    ) * TurnSpeed
}

E:rotat(Ang)
E:move(Pos)
