@name dirmtest
@inputs 
@outputs 
@persist FDir:vector [VA VB VC]:vector T G [VA2 VB2 VC2]:vector G2
@trigger none

if (first()) { 
    holoCreate(1) 
    holoModel(1,"sphere3")
    holoScaleUnits(1,vec(6))
    
    holoCreate(2) 
    holoModel(2,"sphere3")
    holoScaleUnits(2,vec(6))
    
        holoCreate(3) 
    holoModel(3,"sphere3")
    holoScaleUnits(3,vec(6))
    
    VA = VB = VC = VA2 = VB2 = VC2 = entity():pos()
}

interval(60)

Up = vec(0,0,1)

FDot = entity():forward():dot(Up)
RDot = entity():right():dot(Up)

W = owner():keyPressed("up")
A = owner():keyPressed("left")
S = owner():keyPressed("down")
D = owner():keyPressed("right")

MDir = entity():toWorldAxis( vec(-FDot, RDot, 0)*50 + vec( (W-S), (A-D), 0 ):normalized()*50 )
FDir = mix( MDir, FDir, 0.25 )

holoPos(1, entity():pos() + FDir)

if ( T < 1 ) { T += 0.1 } else { T = 0 }

switch (T) {
    case 0, 
        if (G < 1) { }
        else {
            VA = VC
            VC = VC + FDir
            VB = (VA + VC)/2 + vec(0,0,VA:distance(VC))
            
            G = 0 
        }
    break 
    
    case 0.5,
        if (G2 < 1) { }
        else {
            VA2 = VC2
            VC2 = VC2 + FDir
            VB2 = (VA2 + VC2)/2 + vec(0,0,VA2:distance(VC2))
            
            G2 = 0 
        }
    break      
}

G += 0.1
G2 += 0.1

holoPos( 2, bezier(VA,VB,VC,min(G,1)) )
holoPos( 3, bezier(VA2,VB2,VC2,min(G2,1)) )


#entity():propGravity(0)
#entity():applyForce( ( FDir - entity():vel() ) * entity():mass() )
