Springs
Categories:
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
- SimpleSpringDamperExact
- AccelerationSpringDamper
- DoubleSpringDamper
- TimedSpringDamper
- VelocitySpringDamper
- QuaternionSpringDamper
- Usage Example
- See Also
Spring Types
| Type | Character | Best For |
|---|---|---|
SimpleSpringDamperExact | Fast start, ease-out arrival | Simple follow, snap behaviors |
AccelerationSpringDamper | Tracks target velocity, smoother on input changes | Character movement, camera motion |
DoubleSpringDamper | S-curve — slow start AND slow arrival | UI transitions, polished cuts |
TimedSpringDamper | Reaches target by a specified time | Choreographed, loosely timed movements |
VelocitySpringDamper | Predictive — leads the target’s direction | Camera following a moving target |
QuaternionSpringDamper | Rotational 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.
| Parameter | Type | Description |
|---|---|---|
position | T (in/out) | Current position, updated in-place each frame |
velocity | T (in/out) | Current velocity — must be cached between frames |
targetPosition | T | Goal position to move toward |
halflife | float | Seconds to cover 50% of remaining distance |
deltaTime | float | Frame 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.
| Parameter | Type | Description |
|---|---|---|
position | T (in/out) | Accumulated position |
velocity | T (in/out) | Current velocity — must be cached between frames |
acceleration | T (in/out) | Acceleration memory — must be cached between frames |
targetVelocity | T | The desired velocity to spring toward |
halflife | float | Settling time |
deltaTime | float | Frame 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.
| Parameter | Type | Description |
|---|---|---|
position | T (in/out) | Current position |
velocity | T (in/out) | Current velocity — must be cached between frames |
previousPosition | T (in/out) | Internal state — must be cached between frames |
previousVelocity | T (in/out) | Internal state — must be cached between frames |
targetPosition | T | Goal position |
halflife | float | Settling time |
deltaTime | float | Frame 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.
| Parameter | Type | Description |
|---|---|---|
position | T (in/out) | Current position |
velocity | T (in/out) | Current velocity — must be cached between frames |
previousTarget | T (in/out) | Last known target — must be cached between frames |
targetPosition | T | Destination |
targetTime | float | Time (in seconds) at which the spring should arrive |
halflife | float | Base settling time |
deltaTime | float | Frame 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.
| Parameter | Type | Description |
|---|---|---|
position | T (in/out) | Follower position |
velocity | T (in/out) | Follower velocity — must be cached between frames |
previousPosition | T (in/out) | Internal state — must be cached between frames |
targetPosition | T | Current target position |
targetVelocity | T | Target’s velocity (used for predictive lead) |
halflife | float | Settling time |
deltaTime | float | Frame delta time |
QuaternionSpringDamper
Rotation spring that operates on angular velocity. Includes a flip option to reverse the rotation direction.
Note: The
rotationoutput jumps to the goal each frame. ExtractangularVelocityand integrate externally if you need a continuously smooth rotation output.
| Parameter | Type | Description |
|---|---|---|
rotation | AZ::Quaternion (in/out) | Quaternion moved toward targetRotation |
angularVelocity | AZ::Vector3 (in/out) | Angular velocity — must be cached between frames |
targetRotation | AZ::Quaternion | Goal orientation |
halflife | float | Settling time |
deltaTime | float | Frame delta time |
flip | bool | Reverses 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.