Skip to content

Spring

export type Spring<T> = StateObject<T> & {
    kind: "Spring",
    setPosition: (self, newPosition: T) -> (),
    setVelocity: (self, newVelocity: T) -> (),
    addVelocity: (self, deltaVelocity: T) -> ()
}

A specialised state object for following a goal state smoothly over time, using physics to shape the motion.

The methods on this type allow for direct control over the position and velocity of the motion. Other than that, this type is of limited utility outside of Fusion itself.


Members

kind : "Spring"

A more specific type string which can be used for runtime type checking. This can be used to tell types of state object apart.


Methods

setPosition -> ()

function Spring:setPosition(
    newPosition: T
): ()

Immediately snaps the spring to the given position. The position must have the same typeof() as the goal state.

setVelocity -> ()

function Spring:setVelocity(
    newVelocity: T
): ()

Overwrites the spring's velocity without changing its position. The velocity must have the same typeof() as the goal state.

addVelocity -> ()

function Spring:addVelocity(
    deltaVelocity: T
): ()

Appends to the spring's velocity without changing its position. The velocity must have the same typeof() as the goal state.


Learn More

Back to top