@name Friendly Movement
@inputs Pod:wirelink Body:entity
@outputs Holo Spawn Sp
@persist RP RR RY
@outputs Controls CT Active M1 M2
@persist Seat:entity Driver:entity
@trigger 

interval(10)
Body = entity():isWeldedTo()
E = entity()
Body:setMass(5000)

Seat = Pod["Entity",entity]

Controls = Pod:number("Alt")

if(Active==1 && CT == 0){
    CT=1
}
     
if(Active==0){
    CT=0
}
     
if(changed(Controls)&Controls){
    CT+=1
}


if(changed(CT)){
    if(CT == 1){
        hint("WASD Mode Activated.",5)
        Seat:printColorDriver(array(vec(255,0,0),"[E2] ",vec(0,200,200),"Fly Mode Activated."))
    }
    if(CT == 2){
        hint("Mouse Mode Activated.",5)
        Seat:printColorDriver(array(vec(255,0,0),"[E2] ",vec(0,200,200),"Fight Mode Activated."))
    }
    if(CT == 3){
        CT=1
    }
}
#1
if(CT != 1){
    RY = (Body:vel():dot(Body:forward())/100+(entity():angles():roll()/-20))  
}else{
    RY = (M1-M2)*8+(Body:vel():dot(Body:forward())/100+(entity():angles():roll()/-20))
}

if(CT == 1){
    W = Pod["W",number]
    A = Pod["A",number]
    S = Pod["S",number]
    D = Pod["D",number]
    Space = Pod["Space",number]
    Shift = Pod["Shift",number]
    M1 = Pod:number("Mouse1")
    M2 = Pod:number("Mouse2")
    Active = Pod["Active",number]
}

if(CT == 2){
    
}

if(first()|dupefinished()){
    RY = (M1-M2)*8+(Body:vel():dot(Body:forward())/100+(entity():angles():roll()/-20))
    CT=0
}

RP = (W-S)*25+(2.5*(Space==0))-abs(Body:vel():dot(Body:forward())/150+(entity():angles():roll()/-3))
RR = (A-D)*25

Force = 40
Anglo = ang(-Body:angVel():pitch()+RR,-Body:angVel():yaw()/5+RY,-Body:angVel():roll()+RP) * Force * shiftL(ang(Body:inertia()))
Body:applyAngForce(Anglo)


Body:applyForce(Body:up()*Body:mass()*9*Active)#9.3
Body:applyForce(Body:up()*Body:mass()*(Space-Shift)*15)
Body:applyForce(Body:up()*Body:mass()*Body:vel():z()/-100*(abs(entity():angles():pitch())<90))

#switch modes
HeldQuat = inv(quat(Body)) * quat(Body:up(), Body:right())
CurrentQuat = quat(Body) * HeldQuat
