@name Car V1
@inputs 
@outputs Throttle 
@persist [RangerFL RangerFR RangerBL RangerBR]:ranger Hold 
@trigger 
runOnTick(1)

Body = entity():isWeldedTo()

if (first()) {
    holoCreate(1)
    
    holoCreate(2)
    
    holoCreate(3)
    
    holoCreate(4)
    
    Body:setMass(50000)
}

rangerFilter(Body)
RangerFL = rangerOffset(10,Body:toWorld(vec(60,40,10)),-Body:up())
FrontL = RangerFL:distance()

rangerFilter(Body)
RangerFR = rangerOffset(10,Body:toWorld(vec(60,-40,10)),-Body:up())
FrontR =  RangerFR:distance()

rangerFilter(Body)
RangerBL = rangerOffset(10,Body:toWorld(vec(-60,40,10)),-Body:up())
RearL =  RangerBL:distance()

rangerFilter(Body)
RangerBR = rangerOffset(10,Body:toWorld(vec(-60,-40,10)),-Body:up())
RearR =  RangerBR:distance()   

Ranger = min(FrontL,FrontR,RearL,RearR)

holoPos(1,RangerFL:pos())
holoPos(2,RangerFR:pos())
holoPos(3,RangerBL:pos())
holoPos(4,RangerBR:pos())

if (tickClk()) {
    Vel = Body:velL()
    VelX = Vel:x()
    VelY = Vel:y()
    Side = Body:right()
    Forward = Body:forward()
}

ForceStable=((VelY * Side * (1.6)) + (VelX * Forward * (-0.02 - (Hold))))*50000

    Vector =  Forward*Throttle*((3))*13
    Z=(4000)*clamp((10+(30))-Ranger,0,10+(30)) 
    ForceMain=Body:up()*(50000+Z) 
    ForceZ = Body:up()*-Vel:z()*50000/12
    
    
     Body:applyForce((ForceMain+ForceZ+ForceStable+Vector)) 

#Body:applyForce(Body:up()*Body:mass()*60)
