@name wheel_anim
@inputs 
@outputs 
@persist Wheel:entity [Diameter Radius Circumference] DT CT Position:vector Rotation
@trigger none

interval(60)

if (!Wheel) {
    
    Diameter      = 60
    Radius        = Diameter/2
    Circumference = Diameter*pi()
    
    Wheel = holoCreate(1, entity():pos(), vec(Diameter, Diameter, 6)/12)
    
    holoModel(1, "cylinder")
    holoAlpha(1, 0)
    
    holoCreate(2, Wheel:pos())
    holoParent(2, Wheel)
    holoModel(2, "models/sprops/trans/wheel_e/t_wheel60.mdl")
    holoAng(2, Wheel:toWorld(ang(0, 0, 90)))
    
    Position = Wheel:pos() + vec(0, 0, Radius)

    CT = curtime()
    
}

DT = curtime() - CT
CT = curtime()

#- Linear velocity (units per second)
LinearVelocity = 125

#- Angular velocity (revolutions per second)
Revolutions = (LinearVelocity / Circumference)*DT
Rotation = Rotation + 360*Revolutions

#-
local Yaw = (owner():eyeTrace():position() - Position):toAngle():yaw()

Direction = vec(1, 0, 0):rotate(0, Yaw, 0)
Position = Position + Direction*LinearVelocity*DT

local Right = Direction:cross(vec(0, 0, 1))
local Angle = (Direction:toAngle() + ang(0, 0, 90)):rotateAroundAxis( Right, -Rotation )

holoPos(1, Position)
holoAng(1, Angle)
