@name Orbiting ball
@model models/XQM/Rails/trackball_1.mdl
@inputs 
@outputs 
@persist [Gate Target]:entity Vec:vector Ang:angle Rank
@trigger 

if (first()) {
    runOnTick(1)
    runOnChat(1)
    runOnLast(1)
    
    Gate = entity()
    Target = owner()
    
    Num = gGetNum("OrbitNum")
    Rank = Num+1
    gSetNum("OrbitNum",Rank)
}

if (chatClk()) {
    
}

Num = gGetNum("OrbitNum")

if (last()) {
    gSetNum("OrbitNum",Num-1)
    exit()
}

Vec = (Target:shootPos()+vec(cos(curtime()*10+(360/Num)*Rank),sin(curtime()*10+(360/Num)*Rank),sin(curtime()*100)/10)*100-Gate:pos())*100
applyForce(Vec+$Vec*10)

Ang = -Gate:angles()*100
applyAngForce(Ang+$Ang*5)
