UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SpringMath Struct Reference

#include <SpringMath.h>

Static Public Member Functions

static constexpr float SmoothingTimeToHalfLife (float SmoothingTime)
 
static constexpr float HalfLifeToSmoothingTime (float HalfLife)
 
static constexpr float SmoothingTimeToStrength (float SmoothingTime)
 
static constexpr float StrengthToSmoothingTime (float Strength)
 
template<typename T >
static void CriticalSpringDamper (T &InOutX, T &InOutV, T TargetX, float SmoothingTime, float DeltaTime)
 
static void CriticalSpringDamperAngle (float &InOutAngleRadians, float &InOutAngularVelocityRadians, float TargetAngleRadians, float SmoothingTime, float DeltaTime)
 
static void CriticalSpringDamperQuat (FQuat &InOutRotation, FVector &InOutAngularVelocityRadians, const FQuat &TargetRotation, float SmoothingTime, float DeltaTime)
 
template<typename TFloat >
static void VelocitySpringDamperF (TFloat &InOutX, TFloat &InOutV, TFloat &InOutXi, TFloat TargetX, TFloat MaxSpeed, float SmoothingTime, float DeltaTime)
 
template<typename TVector >
static void VelocitySpringDamper (TVector &InOutX, TVector &InOutV, TVector &InOutXi, TVector TargetX, float MaxSpeed, float SmoothingTime, float DeltaTime)
 
template<typename TVector >
static void SpringCharacterUpdate (TVector &InOutPosition, TVector &InOutVelocity, TVector &InOutAcceleration, const TVector &TargetVelocity, float SmoothingTime, float DeltaTime, float VDeadzone=1e-2f, float ADeadzone=1e-4f)
 
template<typename TVector >
static void SpringCharacterPredict (TArrayView< TVector > OutPredictedPositions, TArrayView< TVector > OutPredictedVelocities, TArrayView< TVector > OutPredictedAccelerations, const TVector &CurrentPosition, const TVector &CurrentVelocity, const TVector &CurrentAcceleration, const TVector &TargetVelocity, float SmoothingTime, float SecondsPerPredictionStep, float VDeadzone=1e-2f, float ADeadzone=1e-4f)
 
template<typename TVector >
static void VelocitySpringCharacterUpdate (TVector &InOutPosition, TVector &InOutVelocity, TVector &InOutVelocityIntermediate, TVector &InOutAcceleration, TVector TargetVelocity, float SmoothingTime, float MaxAcceleration, float DeltaTime, float VDeadzone=1e-2f, float ADeadzone=1e-4f)
 
template<typename TVector >
static void VelocitySpringCharacterPredict (TArrayView< TVector > OutPredictedPositions, TArrayView< TVector > OutPredictedVelocities, TArrayView< TVector > OutPredictedIntermediateVelocities, TArrayView< TVector > OutPredictedAccelerations, const TVector &CurrentPosition, const TVector &CurrentVelocity, const TVector &CurrentIntermediateVelocity, const TVector &CurrentAcceleration, const TVector &TargetVelocity, float SmoothingTime, float MaxAcceleration, float SecondsPerPredictionStep, float VDeadzone=1e-2f, float ADeadzone=1e-4f)
 
static void CriticalSpringDamperQuatPredict (TArrayView< FQuat > OutPredictedRotations, TArrayView< FVector > OutPredictedAngularVelocities, int32 PredictCount, const FQuat &CurrentRotation, const FVector &CurrentAngularVelocity, const FQuat &TargetRotation, float SmoothingTime, float SecondsPerPredictionStep)
 
static constexpr void ExponentialSmoothingApproxQuat (FQuat &InOutRotation, const FQuat &InTargetRotation, const float InDeltaTime, const float InSmoothingTime)
 
static constexpr void ExponentialSmoothingApproxAngle (float &InOutAngleRadians, const float &InTargetAngleRadians, const float InDeltaTime, const float InSmoothingTime)
 

Member Function Documentation

◆ CriticalSpringDamper()

template<typename T >
static void SpringMath::CriticalSpringDamper ( T &  InOutX,
T &  InOutV,
TargetX,
float  SmoothingTime,
float  DeltaTime 
)
inlinestatic

Simplified version of FMath::CriticallyDampedSmoothing where v_goal is assumed to be 0. This interpolates the value InOutX towards TargetX with the motion of a critically damped spring. The velocity of InOutX is stored in InOutV.

Template Parameters
TThe type to be damped
Parameters
InOutXThe value to be damped
InOutVThe speed of the value to be damped
TargetXThe goal to damp towards
SmoothingTimeThe smoothing time to use for the spring. Longer times lead to more damped behaviour. A time of 0 will snap InOutX to TargetX
DeltaTimeTimestep in seconds

◆ CriticalSpringDamperAngle()

static void SpringMath::CriticalSpringDamperAngle ( float InOutAngleRadians,
float InOutAngularVelocityRadians,
float  TargetAngleRadians,
float  SmoothingTime,
float  DeltaTime 
)
inlinestatic

Specialized angle version of CriticalSpringDamper that handles angle wrapping.

Parameters
InOutAngleRadiansThe value to be damped
InOutAngularVelocityRadiansThe speed of the value to be damped
TargetAngleRadiansThe goal to damp towards
SmoothingTimeThe smoothing time to use for the spring. Longer times lead to more damped behaviour. A time of 0 will snap InOutAngleRadians to TargetAngleRadians
DeltaTimeTimestep in seconds

◆ CriticalSpringDamperQuat()

static void SpringMath::CriticalSpringDamperQuat ( FQuat InOutRotation,
FVector InOutAngularVelocityRadians,
const FQuat TargetRotation,
float  SmoothingTime,
float  DeltaTime 
)
inlinestatic

Specialized quaternion version of CriticalSpringDamper, uses FVector for angular velocity

Parameters
InOutRotationThe value to be damped
InOutAngularVelocityRadiansThe angular velocity of the rotation in radians
TargetRotationThe target rotation to damp towards
SmoothingTimehe smoothing time to use for the spring. Longer times lead to more damped behaviour. A time of 0 will snap InOutRotation to TargetRotation
DeltaTime

◆ CriticalSpringDamperQuatPredict()

static void SpringMath::CriticalSpringDamperQuatPredict ( TArrayView< FQuat OutPredictedRotations,
TArrayView< FVector OutPredictedAngularVelocities,
int32  PredictCount,
const FQuat CurrentRotation,
const FVector CurrentAngularVelocity,
const FQuat TargetRotation,
float  SmoothingTime,
float  SecondsPerPredictionStep 
)
inlinestatic

Prediction of CriticalSpringDamperQuat

Parameters
OutPredictedRotationsArrayView of output buffer to put the predicted rotations. ArrayView should be the same size as PredictCount
OutPredictedAngularVelocitiesArrayView of output buffer to put the predicted angular velocities. ArrayView should be the same size as PredictCount
PredictCountHow many points to predict. Must be greater than 0
CurrentRotationInitial rotation at t = 0
CurrentAngularVelocityInitial angular velocity at t = 0
TargetRotationThe target rotation
SmoothingTimeThe smoothing time
SecondsPerPredictionStepHow many seconds per prediction step

◆ ExponentialSmoothingApproxAngle()

static constexpr void SpringMath::ExponentialSmoothingApproxAngle ( float InOutAngleRadians,
const float InTargetAngleRadians,
const float  InDeltaTime,
const float  InSmoothingTime 
)
inlinestaticconstexpr

Specialized angle damper, similar to FMath::ExponentialSmoothingApprox but deals correctly with angle wrap-around. Smooths an angle using exponential damping towards a target.

Parameters
InOutAngleRadiansThe angle to be smoothed
InTargetAngleRadiansThe target to smooth towards
InDeltaTimeTime interval
InSmoothingTimeTimescale over which to smooth. Larger values result in more smoothed behaviour. Can be zero.

◆ ExponentialSmoothingApproxQuat()

static constexpr void SpringMath::ExponentialSmoothingApproxQuat ( FQuat InOutRotation,
const FQuat InTargetRotation,
const float  InDeltaTime,
const float  InSmoothingTime 
)
inlinestaticconstexpr

Specialized quaternion damper, similar to FMath::ExponentialSmoothingApprox but for quaternions. Smooths a value using exponential damping towards a target.

Parameters
InOutRotationThe value to be smoothed
InTargetRotationThe target to smooth towards
InDeltaTimeTime interval
InSmoothingTimeTimescale over which to smooth. Larger values result in more smoothed behaviour. Can be zero.

◆ HalfLifeToSmoothingTime()

static constexpr float SpringMath::HalfLifeToSmoothingTime ( float  HalfLife)
inlinestaticconstexpr

Convert a halflife to a smoothing time

Parameters
HalfLifeThe half life of the spring. How long it takes the value to get halfway towards the target.
Returns
The smoothing time of the spring in seconds. It is the time by which the output lags the input when critically damped, when the input is changing at a constant rate.

◆ SmoothingTimeToHalfLife()

static constexpr float SpringMath::SmoothingTimeToHalfLife ( float  SmoothingTime)
inlinestaticconstexpr

Convert a smoothing time to a half life

Parameters
SmoothingTimeThe smoothing time of the spring in seconds. It is the time by which the output lags the input when critically damped, when the input is changing at a constant rate.
Returns
The half life of the spring. How long it takes the value to get halfway towards the target.

◆ SmoothingTimeToStrength()

static constexpr float SpringMath::SmoothingTimeToStrength ( float  SmoothingTime)
inlinestaticconstexpr

Convert from smoothing time to spring strength.

Parameters
SmoothingTimeThe smoothing time of the spring in seconds. It is the time by which the output lags the input when critically damped, when the input is changing at a constant rate.
Returns
The spring strength. This corresponds to the undamped frequency of the spring in hz.

◆ SpringCharacterPredict()

template<typename TVector >
static void SpringMath::SpringCharacterPredict ( TArrayView< TVector >  OutPredictedPositions,
TArrayView< TVector >  OutPredictedVelocities,
TArrayView< TVector >  OutPredictedAccelerations,
const TVector &  CurrentPosition,
const TVector &  CurrentVelocity,
const TVector &  CurrentAcceleration,
const TVector &  TargetVelocity,
float  SmoothingTime,
float  SecondsPerPredictionStep,
float  VDeadzone = 1e-2f,
float  ADeadzone = 1e-4f 
)
inlinestatic

Gives predicted positions, velocities and accelerations for SpringCharacterUpdate. Useful for generating a predicted trajectory given known initial start conditions.

Template Parameters
TVectorThe type of vector to use (e.g. FVector2D, FVector4, FVector etc)
Parameters
OutPredictedPositionsArrayView of output buffer to put the predicted positions. ArrayView should be the same size as PredictCount
OutPredictedVelocitiesArrayView of output buffer to put the predicted velocities. ArrayView should be the same size as PredictCount
OutPredictedAccelerationsArrayView of output buffer to put the predicted accelerations. ArrayView should be the same size as PredictCount
PredictCountHow many points to predict. Must be greater than 0
CurrentPositionThe initial position of the character
CurrentVelocityThe initial velocity of the character
CurrentAccelerationThe initial acceleration of the character
TargetVelocityThe target velocity of the character
SmoothingTimeThe smoothing time of the character. It takes roughly the smoothing time in order for the character to reach the target velocity.
SecondsPerPredictionStepHow much time in between each prediction step.
VDeadzoneDeadzone for velocity. Current velocity will snap to target velocity when within the deadzone
ADeadzoneDeadzone for acceleration. Acceleration will snap to zero when within the deadzone

◆ SpringCharacterUpdate()

template<typename TVector >
static void SpringMath::SpringCharacterUpdate ( TVector &  InOutPosition,
TVector &  InOutVelocity,
TVector &  InOutAcceleration,
const TVector &  TargetVelocity,
float  SmoothingTime,
float  DeltaTime,
float  VDeadzone = 1e-2f,
float  ADeadzone = 1e-4f 
)
inlinestatic

Update the position of a character given a target velocity using a simple damped spring

Template Parameters
TVectorThe type of vector to use (e.g. FVector2D, FVector4, FVector etc)
Parameters
InOutPositionThe position of the character
InOutVelocityThe velocity of the character. Needs to be stored and persisted by the caller. Usually initialized to zero and not modified by the caller.
InOutAccelerationThe acceleration of the character. Needs to be stored and persisted by the caller. Usually initialized to zero and not modified by the caller.
TargetVelocityThe target velocity of the character.
SmoothingTimeThe time over which to smooth velocity. It takes roughly the smoothing time in order for the character to reach the target velocity.
DeltaTimeThe delta time to tick the character
VDeadzoneDeadzone for velocity. Current velocity will snap to target velocity when within the deadzone
ADeadzoneDeadzone for acceleration. Acceleration will snap to zero when within the deadzone

◆ StrengthToSmoothingTime()

static constexpr float SpringMath::StrengthToSmoothingTime ( float  Strength)
inlinestaticconstexpr

Convert from spring strength to smoothing time.

Parameters
StrengthThe spring strength. This corresponds to the undamped frequency of the spring in hz.
Returns
The smoothing time of the spring in seconds. It is the time by which the output lags the input when critically damped, when the input is changing at a constant rate.

◆ VelocitySpringCharacterPredict()

template<typename TVector >
static void SpringMath::VelocitySpringCharacterPredict ( TArrayView< TVector >  OutPredictedPositions,
TArrayView< TVector >  OutPredictedVelocities,
TArrayView< TVector >  OutPredictedIntermediateVelocities,
TArrayView< TVector >  OutPredictedAccelerations,
const TVector &  CurrentPosition,
const TVector &  CurrentVelocity,
const TVector &  CurrentIntermediateVelocity,
const TVector &  CurrentAcceleration,
const TVector &  TargetVelocity,
float  SmoothingTime,
float  MaxAcceleration,
float  SecondsPerPredictionStep,
float  VDeadzone = 1e-2f,
float  ADeadzone = 1e-4f 
)
inlinestatic

Gives predicted positions, velocities and accelerations for SpringCharacterUpdate. Useful for generating a predicted trajectory given known initial start conditions.

Template Parameters
TVectorThe type of vector to use (e.g. FVector2D, FVector4, FVector etc)
Parameters
OutPredictedPositionsArrayView of output buffer to put the predicted positions. ArrayView should be the same size as PredictCount
OutPredictedVelocitiesArrayView of output buffer to put the predicted velocities. ArrayView should be the same size as PredictCount
OutPredictedIntermediateVelocitiesArrayView of output buffer to put the predicted intermediate velocities. ArrayView should be the same size as PredictCount
OutPredictedAccelerationsArrayView of output buffer to put the predicted accelerations. ArrayView should be the same size as PredictCount
PredictCountHow many points to predict. Must be greater than 0
CurrentPositionThe initial position of the character
CurrentVelocityThe initial velocity of the character
CurrentIntermediateVelocityThe initial intermediate velocity of the character
CurrentAccelerationThe initial acceleration of the character
TargetVelocityThe target velocity of the character
SmoothingTimeThe smoothing time of the character. It takes roughly the smoothing time in order for the character to reach the target velocity.
MaxAccelerationPuts a limit on the maximum acceleration that the intermediate velocity can do each frame. If MaxAccel is very large, the behaviour wil lbe the same as SpringCharacterUpdate
SecondsPerPredictionStepHow much time in between each prediction step.
VDeadzoneDeadzone for velocity. Current velocity will snap to target velocity when within the deadzone
ADeadzoneDeadzone for acceleration. Acceleration will snap to zero when within the deadzone

◆ VelocitySpringCharacterUpdate()

template<typename TVector >
static void SpringMath::VelocitySpringCharacterUpdate ( TVector &  InOutPosition,
TVector &  InOutVelocity,
TVector &  InOutVelocityIntermediate,
TVector &  InOutAcceleration,
TVector  TargetVelocity,
float  SmoothingTime,
float  MaxAcceleration,
float  DeltaTime,
float  VDeadzone = 1e-2f,
float  ADeadzone = 1e-4f 
)
inlinestatic

Update a position representing a character given a target velocity using a velocity spring. A velocity spring tracks an intermediate velocity which moves at a maximum acceleration linearly towards a target. This means unlike the "SpringCharacterUpdate", it will take longer to reach a target velocity that is further away from the current velocity.

Template Parameters
TVectorThe type of vector to use (e.g. FVector2D, FVector4, FVector etc)
Parameters
InOutPositionThe position of the character
InOutVelocityThe velocity of the character. Needs to be stored and persisted by the caller. Usually initialized to zero and not modified by the caller.
InOutVelocityIntermediateThe intermediate velocity of the character. Needs to be stored and persisted by the caller. Usually initialized to zero and not modified by the caller.
InOutAccelerationThe acceleration of the character. Needs to be stored and persisted by the caller. Usually initialized to zero and not modified by the caller.
TargetVelocityThe target velocity of the character.
SmoothingTimeThe time over which to smooth velocity. It takes roughly the smoothing time in order for the character to reach the target velocity.
MaxAccelerationPuts a limit on the maximum acceleration that the intermediate velocity can do each frame. If MaxAccel is very large, the behaviour wil lbe the same as SpringCharacterUpdate
DeltaTimeThe delta time to tick the character
VDeadzoneDeadzone for velocity. Current velocity will snap to target velocity when within the deadzone
ADeadzoneDeadzone for acceleration. Acceleration will snap to zero when within the deadzone

◆ VelocitySpringDamper()

template<typename TVector >
static void SpringMath::VelocitySpringDamper ( TVector &  InOutX,
TVector &  InOutV,
TVector &  InOutXi,
TVector  TargetX,
float  MaxSpeed,
float  SmoothingTime,
float  DeltaTime 
)
inlinestatic

A velocity spring will damp towards a target that follows a fixed linear target velocity, allowing control of the interpolation speed while still giving a smoothed behaviour. A SmoothingTime of 0 will give a linear interpolation between X and TargetX

Template Parameters
TVectorThe type of vector to use (e.g. FVector2D, FVector4, FVector etc)
Parameters
InOutXThe value to be damped
InOutVThe velocity of the value to be damped
InOutXiThe intermediate target of the value to be damped
TargetXThe target value of X to damp towards
MaxSpeedThe max velocity to use for the intermediate target interpolation
SmoothingTimeThe smoothing time to use while damping towards X. Higher values will give more smoothed behaviour. A value of 0 will give a linear interpolation of X to Target
DeltaTimeThe timestep in seconds

◆ VelocitySpringDamperF()

template<typename TFloat >
static void SpringMath::VelocitySpringDamperF ( TFloat InOutX,
TFloat InOutV,
TFloat InOutXi,
TFloat  TargetX,
TFloat  MaxSpeed,
float  SmoothingTime,
float  DeltaTime 
)
inlinestatic

A velocity spring will damp towards a target that follows a fixed linear target velocity, allowing control of the interpolation speed while still giving a smoothed behavior. A SmoothingTime of 0 will give a linear interpolation between X and TargetX

Parameters
InOutXThe value to be damped
InOutVThe velocity of the value to be damped
InOutXiThe intermediate target of the value to be damped
TargetXThe target value of X to damp towards
MaxSpeedThe desired speed to achieve while damping towards X
SmoothingTimeThe smoothing time to use while damping towards X. Higher values will give more smoothed behaviour. A value of 0 will give a linear interpolation of X to Target
DeltaTimeThe timestep in seconds

The documentation for this struct was generated from the following file: