Springs

Spring-damper functions for physically-grounded value interpolation — smooth following, overshoot, and settling for floats, vectors, and quaternions.

The Springs namespace (GS_Core::Springs) provides six spring-damper types for physics-based animation and smoothing. Springs produce natural-feeling motion that reacts to velocity — ideal for camera follow, UI motion, and any value that should settle rather than snap.

All springs use a halflife parameter: the number of seconds to cover 50% of the remaining distance to the goal. This is more intuitive than raw stiffness/damping constants. Each spring type is available in float, AZ::Vector2, and AZ::Vector3 overloads where applicable.

Used by: gs_phantomcam (camera smoothing), gs_unit (character movement), gs_juice (feedback motions)

For usage guides and setup examples, see The Basics: GS_Core.

 

Contents


Spring Types

TypeCharacterBest For
SimpleSpringDamperExactFast start, ease-out arrivalSimple follow, snap behaviors
AccelerationSpringDamperTracks target velocity, smoother on input changesCharacter movement, camera motion
DoubleSpringDamperS-curve — slow start AND slow arrivalUI transitions, polished cuts
TimedSpringDamperReaches target by a specified timeChoreographed, loosely timed movements
VelocitySpringDamperPredictive — leads the target’s directionCamera following a moving target
QuaternionSpringDamperRotational spring (angular velocity)Smooth orientation changes

SimpleSpringDamperExact

A critically-damped spring that moves toward a target position. Fast start, ease-out arrival. Computed exactly (no approximation). The most common spring for follow and snap behaviors.

ParameterTypeDescription
positionT (in/out)Current position, updated in-place each frame
velocityT (in/out)Current velocity — must be cached between frames
targetPositionTGoal position to move toward
halflifefloatSeconds to cover 50% of remaining distance
deltaTimefloatFrame delta time

AccelerationSpringDamper

Tracks a target velocity rather than a position. Adds an acceleration memory term for smoother response to sudden direction changes (e.g. thumbstick flicks). Suited for character movement and camera motion where input can change abruptly.

ParameterTypeDescription
positionT (in/out)Accumulated position
velocityT (in/out)Current velocity — must be cached between frames
accelerationT (in/out)Acceleration memory — must be cached between frames
targetVelocityTThe desired velocity to spring toward
halflifefloatSettling time
deltaTimefloatFrame delta time

DoubleSpringDamper

Two springs chained together, producing an S-curve (ease-in AND ease-out). Slower to start and slower to arrive than the simple spring. Gives a more polished feel for UI transitions or cinematic camera cuts.

ParameterTypeDescription
positionT (in/out)Current position
velocityT (in/out)Current velocity — must be cached between frames
previousPositionT (in/out)Internal state — must be cached between frames
previousVelocityT (in/out)Internal state — must be cached between frames
targetPositionTGoal position
halflifefloatSettling time
deltaTimefloatFrame delta time

TimedSpringDamper

Attempts to reach the target by a specific time. Adjusts halflife internally so the spring arrives near the target time rather than asymptotically. Useful for choreographed movements with loose time targets.

ParameterTypeDescription
positionT (in/out)Current position
velocityT (in/out)Current velocity — must be cached between frames
previousTargetT (in/out)Last known target — must be cached between frames
targetPositionTDestination
targetTimefloatTime (in seconds) at which the spring should arrive
halflifefloatBase settling time
deltaTimefloatFrame delta time

VelocitySpringDamper

Tracks a moving target by incorporating the target’s own velocity for predictive lead. The follower anticipates the direction of movement, reducing lag on fast-moving targets. Suited for camera following a character at speed.

ParameterTypeDescription
positionT (in/out)Follower position
velocityT (in/out)Follower velocity — must be cached between frames
previousPositionT (in/out)Internal state — must be cached between frames
targetPositionTCurrent target position
targetVelocityTTarget’s velocity (used for predictive lead)
halflifefloatSettling time
deltaTimefloatFrame delta time

QuaternionSpringDamper

Rotation spring that operates on angular velocity. Includes a flip option to reverse the rotation direction.

Note: The rotation output jumps to the goal each frame. Extract angularVelocity and integrate externally if you need a continuously smooth rotation output.

ParameterTypeDescription
rotationAZ::Quaternion (in/out)Quaternion moved toward targetRotation
angularVelocityAZ::Vector3 (in/out)Angular velocity — must be cached between frames
targetRotationAZ::QuaternionGoal orientation
halflifefloatSettling time
deltaTimefloatFrame delta time
flipboolReverses rotation direction (default: false)

Usage Example

#include <GS_Core/Utility/Math/SpringsUtility.h>

// Member fields — must persist between frames
AZ::Vector3 m_followVelocity = AZ::Vector3::CreateZero();

// In your tick function:
AZ::Vector3 currentPos = GetEntityTranslation();
AZ::Vector3 targetPos  = GetTargetTranslation();

GS_Core::Springs::SimpleSpringDamperExact(
    currentPos,       // in/out: current position (updated in place)
    m_followVelocity, // in/out: velocity (cached between frames)
    targetPos,        // target position
    0.1f,             // halflife: 0.1 seconds to cover half the distance
    deltaTime
);

SetEntityTranslation(currentPos);

See Also

For related resources:


Get GS_Core

GS_Core — Explore this gem on the product page and add it to your project.