@name The Father
@persist N [E Ft Ft2]:entity Rt Ntpl

interval(50)

if(first())
{
    Ntpl = 50/(500/33)
    
    function number cosine(A,B,C)
    {
        return acos((A^2+B^2-C^2)/(2*A*B))
    }
    
    function ik(L1,L2,Hip:entity,Foot:entity,Chassis:entity,I1,I2)
    {    
        local Axis = Chassis:toLocalAxis(Foot:pos()-Hip:pos())
        local Angle = Axis:toAngle():setRoll(-bearing(Hip:pos(),Chassis:angles(),Foot:pos()))
        local Dist = min(Axis:length(),L1+L2)
        local Quat = quat(Angle)*qRotation(vec(0,90+cosine(Dist,L1,L2),0))
        
        holoAng(I1,Chassis:toWorld(Quat:toAngle()))
        holoAng(I2,Hip:toWorld(ang(cosine(L2,L1,Dist)+180,0,0)))
    }
    
    E = entity()
    
    holoCreate(2,E:toWorld(vec(0,5,0)),vec(0.3))
    holoDisableShading(2,1)
    holoParent(2,E)
    
    holoCreate(12,holoEntity(2):pos()+vec(0,0,12),vec(0.25,0.25,2))
    holoDisableShading(12,1)
    holoParent(12,2)
    
    holoCreate(3,holoEntity(2):pos()+vec(0,0,24),vec(0.3))
    holoDisableShading(3,1)
    holoParent(3,2)
    
    holoCreate(13,holoEntity(3):pos()+vec(0,0,12),vec(0.25,0.25,2))
    holoDisableShading(13,1)
    holoParent(13,3)
    
    holoCreate(4,holoEntity(3):pos()+vec(0,0,24),vec(0.6,0.4,0.3))
    holoDisableShading(4,1)
    holoParent(4,3)
    
    Ft = holoCreate(5)
    holoAlpha(5,0)
    
    ###
    
    holoCreate(20,E:toWorld(vec(0,-5,0)),vec(0.3))
    holoDisableShading(20,1)
    holoParent(20,E)
    
    holoCreate(120,holoEntity(20):pos()+vec(0,0,12),vec(0.25,0.25,2))
    holoDisableShading(120,1)
    holoParent(120,20)
    
    holoCreate(30,holoEntity(20):pos()+vec(0,0,24),vec(0.3))
    holoDisableShading(30,1)
    holoParent(30,20)
    
    holoCreate(130,holoEntity(30):pos()+vec(0,0,12),vec(0.25,0.25,2))
    holoDisableShading(130,1)
    holoParent(130,30)
    
    holoCreate(40,holoEntity(30):pos()+vec(0,0,24),vec(0.6,0.4,0.3))
    holoDisableShading(40,1)
    holoParent(40,30)
    
    Ft2 = holoCreate(50)
    holoAlpha(50,0)
    
    Rt = 0
}

if((changed(owner():keyUse())&owner():keyUse())|(changed(owner():keyAttack2())&owner():keyAttack2()))
{
    Rt+=(owner():keyUse()-owner():keyAttack2())*2
}
    

N+=Rt*Ntpl
#N += -E:velL():x()/20/2/pi()/(40+sin(N+15)*7.5)*360

###

Ang = entity():toWorld(ang(90+cos(N)*60,0,0))

RD = rangerOffset(40+sin(N+15)*7.5,E:toWorld(vec(0,6,0)),Ang:forward())

holoPos(5,RD:pos())

ik(24,24,holoEntity(2),Ft,E,2,3)

if(changed(RD:hit())&RD:hit())
{
    Ft:soundPlay("ftstp",0.3,"player/footsteps/"+RD:matType()+randint(1,6)+".wav")
}

###

Ang2 = entity():toWorld(ang(90+cos(N)*-60,0,0))

RD2 = rangerOffset(40+sin(N+15)*-7.5,E:toWorld(vec(0,-6,0)),Ang2:forward())

holoPos(50,RD2:pos())

ik(24,24,holoEntity(20),Ft2,E,20,30)

if(changed(RD2:hit())&RD2:hit())
{
    Ft2:soundPlay("ftstp2",0.3,"player/footsteps/"+RD2:matType()+randint(1,6)+".wav")
}
