@name mrev
@inputs 
@outputs Cycle
@persist [Cycle] [Gaits]:table [WorldDown]:vector Entity:entity
@trigger none

if ( first() ) {
    Entity = entity()
    WorldDown = vec(0, 0, -1)    
    
    function createGait( Name:string, Offset:vector, Trigger ) {
        Gaits[Name, table] = table(
            "Offset" = Offset,
            "Trigger" = Trigger,
            "Index" = hash(Name),
            "MoveFrom" = Entity:toWorld(Offset),
            "Output" = Entity:toWorld(Offset)
        )    
        
        holoCreate(hash(Name))
    }
    
    createGait( "test1", vec(50,50,0), 0.0 )
    createGait( "test2", vec(50,-50,0), 0.5 )
    createGait( "test3", vec(-50,50,0), 0.75 )
    createGait( "test4", vec(-50,-50,0), 0.25 )
}

interval(60)

foreach (K, Gait:table = Gaits) {
    if ( Cycle == Gait["Trigger", number] ) { 
        Gait["Cycle", number] = 0
        Gait["MoveFrom", vector] = Gait["Output", vector] 
    }
    
    if ( Gait["Cycle", number] < 1 ) {
        Gait["Cycle", number] = Gait["Cycle", number] + 0.1
        Gait["Output", vector]  = mix(rangerOffset(1000, Entity:toWorld(Gait["Offset", vector]) + Entity:vel(), WorldDown):position(), Gait["MoveFrom", vector], Gait["Cycle", number] )
        Gait["Output", vector] = Gait["Output", vector] + vec(0, 0, sin(Gait["Cycle", number]*180)*25)
        holoPos(Gait["Index", number], Gait["Output", vector])
    }
}
if ( Cycle < 1 ) { Cycle += 0.025 } else { Cycle = 0 }

entity():propGravity(0)
T = sin(curtime()*50)*50
entity():applyForce( (entity():forward()*T-entity():vel())*entity():mass() )

