@name Mech Wing Folding
@inputs 
@outputs 
@persist A State 
@trigger 
interval(30)

E = entity()

if (first() | dupefinished()) {
    #RJoint1
    holoCreate(1)
    holoPos(1,E:toWorld(vec(4,0,5)))
    holoScale(1,vec(0.1))
    holoColor(1,vec(0))
    holoParent(1,E)
    
    #LJoint1
    holoCreate(2)
    holoPos(2,E:toWorld(vec(-4,0,5)))
    holoScale(2,vec(0.1))
    holoColor(2,vec(0))
    holoParent(2,E)
    
    #RArm1
    holoCreate(3)
    holoPos(3,E:toWorld(vec(10.6,0,5)))
    holoScale(3,vec(1,0.15,0.15))
    holoParent(3,1)
    
    #LArm1
    holoCreate(4)
    holoPos(4,E:toWorld(vec(-10.6,0,5)))
    holoScale(4,vec(1,0.15,0.15))
    holoParent(4,2)
    
    #RJoint2
    holoCreate(5)
    holoPos(5,E:toWorld(vec(17.2,0,5)))
    holoScale(5,vec(0.1))
    holoColor(5,vec(0))
    holoParent(5,3)
    
    #LJoint2
    holoCreate(6)
    holoPos(6,E:toWorld(vec(-17.2,0,5)))
    holoScale(6,vec(0.1))
    holoColor(6,vec(0))
    holoParent(6,4)
    
    #RArm2
    holoCreate(7)
    holoPos(7,E:toWorld(vec(23.8,0,5)))
    holoScale(7,vec(1,0.1,0.1))
    holoParent(7,5)
    
    #LArm2
    holoCreate(8)
    holoPos(8,E:toWorld(vec(-23.8,0,5)))
    holoScale(8,vec(1,0.1,0.1))
    holoParent(8,6)
    
    holoCreate(9)
    holoModel(9,"models/xqm/jetwing2.mdl")
    holoPos(9,E:toWorld(vec(40,-1,5)))
    holoAng(9,E:toWorld(ang(-90,-90,0)))
    holoParent(9,5)
    
    holoCreate(10)
    holoModel(10,"models/xqm/jetwing2.mdl")
    holoPos(10,E:toWorld(vec(-40,-1,5)))
    holoAng(10,E:toWorld(ang(-90,90,0)))
    holoParent(10,6)
    
    holoCreate(11)
    holoModel(11,"models/xqm/jetengine.mdl")
    holoPos(11,E:toWorld(vec(23.8,-15,10)))
    holoAng(11,E:toWorld(ang(-90,90,0)))
    holoParent(11,5)
    
    holoCreate(12)
    holoModel(12,"models/xqm/jetengine.mdl")
    holoPos(12,E:toWorld(vec(-23.8,-15,10)))
    holoAng(12,E:toWorld(ang(-90,90,0)))
    holoParent(12,6)
}

R = owner():keyWalk()

if (changed(R) & R) {if(State == 0) {State = 1} else {State = 0}}

A += clamp(State*50 - A,-1,1)

holoAng(1,entity():toWorld(ang(A,0,0)))
holoAng(2,entity():toWorld(ang(-A,0,0)))
holoAng(5,holoEntity(1):toWorld(ang(A,0,0)))
holoAng(6,holoEntity(2):toWorld(ang(-A,0,0)))

holoAng(11,E:toWorld(ang(-90,90,0)))
holoAng(12,E:toWorld(ang(-90,90,0)))
