Verse Library verse

02 Standalone

Enables perpetual vertical rotation for entities using sequential keyframe steps.

verse-library/verse-anim-rotate-spin/02-standalone.verse

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<final_super>(component):

    # Seconds for ONE full turn. Smaller = faster spin.
    @editable
    var SecondsPerTurn<public>:float = 4.0

    OnBeginSimulation<override>():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{}

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in