@name step_test_2
@inputs 
@outputs
@persist [StepDelay StepRate StepDist] [CurTime DeltaTime]
@persist [StepStage] [StepP0 StepP1 StepP2 StepP3]:vector [StepFrac]
@trigger none


if (first()) {
    
    StepDelay = 1     # delay between steps (in seconds)
    StepRate  = 50    # how fast a step progresses (units per second)
    StepDist  = 50    # step distance (in units)
    
    StepP0 = entity():pos()
    StepP1 = entity():pos()
    StepP2 = entity():pos()
    StepP3 = entity():pos()
    
    CurTime = curtime()
    
    holoCreate(1, StepP3)

}


#-- Calculate delta time
interval(90)

DeltaTime = curtime() - CurTime
CurTime   = curtime()


#-- Calculate new step
if (StepStage == 0) {
    local StepDir = vec(1, 0, 0)
    local StepVec = StepDir*StepDist
    
    #-- set step origin to current pos
    StepP0 = StepP3 
    
    #-- set step target to current pos + stepvec                    
    StepP2 = StepP3 + StepVec   
    
    #-- set step height        
    StepP1 = (StepP0 + StepP2)/2 + vec(0, 0, StepP0:distance(StepP2)/3)
    
    #-- reset step frac
    StepFrac = 0
    
    #-- set step stage
    StepStage = 1
}


#-- Run calculated step
if (StepStage == 1) {
    #-- increment step frac
    StepFrac = min(StepFrac + StepRate*DeltaTime, StepDist)
    
    #-- calculate bezier curve
    StepP3   = bezier(StepP0, StepP1, StepP2, StepFrac/StepDist)
 
    holoPos(1, StepP3)
    
    #-- set step stage
    if (StepFrac == StepDist) {  
        StepFrac  = CurTime
        StepStage = 2
    }
}


#-- Wait 
if (StepStage == 2) {
    if (min(CurTime - StepFrac, StepDelay) == StepDelay) {  
        StepStage = 0
    }
}

