@name Mecha
@inputs P:wirelink
@outputs 
@persist Speed SPACE Props:array Walk_sound Walk_l Walk_s Walk_i E:entity H:array R1:angle R2:angle Lvel:vector
@model 
@trigger 
interval(20)
if(first() | duped())
{
E=entity()
Props=E:getConstraints()
#holoCreate(0,E:pos(),vec(1,2,1),E:angles())

holoCreate(1,E:pos(),vec(2,0.5,0.5)*0.95,E:angles())
holoCreate(2,E:pos(),vec(2,0.5,0.5)*0.95,E:angles())



holoMaterial(1,"phoenix_storms/mat/mat_phx_metallic")
holoMaterial(2,"phoenix_storms/mat/mat_phx_metallic")



holoColor(1,vec(130,130,255))
holoColor(2,vec(70,70,255))

H[0,entity]=holoEntity(0)
H[1,entity]=holoEntity(1)
Walk_s=20
Walk_l=60
E:setMass(100)
}
rangerHitWater(1)
rangerFilter(E)
rangerFilter(Props)
R=rangerOffset(46,E:pos(),vec(0,0,-1))
Speed=E:velL():x()
Turn_speed=E:angVel():yaw()/19
W=P["W",number]
A=P["A",number]
S=P["S",number]
D=P["D",number]
ACT=P["Active",number]
SHIFT=P["Shift",number]
SPACE=P["Space",number]
CONTROL=P["Control",number]
M1=P["Mouse1",number]
Walk_l=abs(Speed/6)
Walk_i+=Walk_s*((E:velL():x()>0)*2 -1)
if(Walk_sound<Walk_i)
    {
    Walk_sound=Walk_i+180

    soundVolume(0,min(abs(E:velL():x())/110,1))
    }
Sin=sin(Walk_i)
Cos=cos(Walk_i)
Dist_v=acos((min(R:distance(),41))/41)
W_sub_T=Walk_l-Turn_speed
W_plus_T=Walk_l+Turn_speed
R1=E:toWorld(ang(Sin*W_plus_T+90-Dist_v,0,0))
R2=E:toWorld(ang((Sin-Cos)*W_plus_T +Walk_l+90+Dist_v,0,0))
E_R=E:right()*10
E_F=-E:forward()*6
holoPos(1,E_F+E_R+E:pos()+R1:forward()*10)
holoAng(1,R1)
holoPos(2,E_F+E_R+E:pos()+R1:forward()*20 + R2:forward()*10)
holoAng(2,R2)

holoAng(6,R2+ang(Dist_v,0,0))

R1=E:toWorld(ang(-Sin*W_sub_T+90-Dist_v,0,0))
R2=E:toWorld(ang((-Sin+Cos)*W_sub_T +Walk_l+90+Dist_v,0,0))
holoPos(3,E_F-E_R+E:pos()+R1:forward()*10)
holoAng(3,R1)
holoPos(4,E_F-E_R+E:pos()+R1:forward()*20 + R2:forward()*10)
holoAng(4,R2)


holoAng(5,R2+ang(Dist_v,0,0))
if(R:hit())
{
E:applyForce(E:forward()*1040*(W-S)*(0.5+SHIFT/2)+vec(0,0,-20+ACT*20-SPACE*17+($SPACE & !SPACE)*(300-R:distance()*6)+46-CONTROL*30-R:distance()+cos(Walk_i*2)*Walk_l/6)*300 - E:vel()*vec(2.3,2.3,20) +E:right()*E:velL():y()*30)
E:applyAngForce(ang(min($Speed*3,0),(A-D)*30,-Sin*Walk_l/2 + E:velL():y()*1.5)*100-E:angles()*ang(1,0,1)*300-E:angVel()*30)
}
