@name Default Mech Example
@inputs Pod:wirelink  
@outputs Ran Props:array Refire GT:array Start
@persist E:entity N Radius X X2 Foot:array Active Height Yaw Shift Space Jump OnGround Alt
@persist Mod G1:ranger G2:ranger GL:array 
runOnTick(1)
rangerPersist(1)

if(first()|dupefinished()) {
    E=entity():isWeldedTo()
    E:setMass(500)
            
    function number cosine(A, B, C){
        return acos((A^2 + B^2 - C^2) / (2*A*B))
    }
    rangerFilter(E)
    Radius=40
}

Vel = E:velL():y()/8
Seat = Pod["Entity",entity]
Driver = Seat:driver()
W = Driver:keyForward()
A = Driver:keyLeft()
S = Driver:keyBack()
D = Driver:keyRight()
Alt = Driver:keyWalk()
Space = Driver:keyJump()
Mouse1 = Driver:keyAttack1()
Mouse2 = Driver:keyAttack2()
Shift = Driver:keySprint()
Active = Driver:isPlayer()
Fade = !Active
Mod = clamp(Mod,250,1000) 

if (Active==1) {
    G1=rangerOffset(50000,holoEntity(65):pos(),holoEntity(65):forward())
    G2=rangerOffset(50000,holoEntity(66):pos(),holoEntity(66):forward())
    if(!Alt&!Space){Height=100}
    if(OnGround){Radius=50}
    else{Radius=0}
    if(Space){Mod+=4}
    if($Space&!Space&OnGround){Mod}
    if(OnGround==0){Mod=0}
}

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

X2 = clamp(X2,-3,3)

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

rangerFilter(E)
RR = rangerOffset(E:toWorld(vec(0,-20,0)),E:toWorld(vec(cos(N-180)*Radius,-20,-105+max(sin(N-180)*Radius*1.5*(W-S),0))))

rangerFilter(E)
RL = rangerOffset(E:toWorld(vec(0,20,0)),E:toWorld(vec(cos(N)*Radius,20,-105+max(sin(N)*Radius*1.5*(W-S),0))))

if ((W|S)&OnGround==1) {
    if (X){X2-=0.18*(Shift+1)}
    
    if (!X){X2+=0.18*(Shift+1)}
    
    if (W){N+=2*(Shift+1)*((S-W)*5)}
    
    if (S){N+=2*(Shift+1)*((W-S)*5)}
    
    if($Space&!Space&OnGround){Jump=Mod}
    
    if((changed(RR:hit())&RR:hit())|(changed(RL:hit())&RL:hit())){
        Ran=int(random(1,9))
        X=!X
    }
} else {X2=0}
 
rangerFilter(E) 
R = rangerOffset(E:pos(),E:pos()-vec(0,0,120))

if (R:hit()) {
    OnGround = 1
    Diff = Height+sin(N*2)*(Shift+1)-R:distance()
    
    E:applyForce(vec(0,0,Diff)*2*E:mass()-(E:vel())*E:mass()+E:forward()*(W-S)*200/(Alt+1)/(Space+1)*(Shift+1)*E:mass()+E:up()*Jump*E:mass())
} else {OnGround=0}

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(X2):setYaw(E:angles():yaw()+Yaw))
