using { /Verse.org/SceneGraph } using { /Verse.org/SceneGraph/KeyframedMovement } using { /Verse.org/Simulation } using { /Verse.org/SpatialMath } # Bolt this onto an entity that also has a Keyframed Movement component to # make it spin forever around its vertical axis — like a trophy on a # rotating display, or a coin pickup catching the light. spin_forever_component := class(component): # Seconds for ONE full turn. Smaller = faster spin. @editable var SecondsPerTurn:float = 4.0 OnBeginSimulation():void = (super:)OnBeginSimulation() if (Mover := Entity.GetComponent[keyframed_movement_component]): # The vertical axis. Spinning around Up turns us like a turntable. SpinAxis := vector3{ Left := 0.0, Up := 1.0, Forward := 0.0 } # One third of a full turn. ThirdTurn := MakeRotationDegrees(SpinAxis, 120.0) # Each step lasts a third of the total turn time. StepSeconds := SecondsPerTurn / 3.0 # One 120-degree step. A constant (linear) speed keeps the spin # even, with no slow-down between hops. Step := keyframed_movement_delta: Duration := StepSeconds Easing := linear_easing_function{} Transform := transform: Rotation := ThirdTurn # Three identical steps = one full circle. Steps := array{ Step, Step, Step } # Loop mode replays the three steps forever: endless smooth spin. Mover.SetKeyframes(Steps, loop_keyframed_movement_playback_mode{}) Mover.Play()