FMath::SpringDamper
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Full spring-damper simulation supporting under-, over-, and critically-damped motion. More flexible than CriticallyDampedSmoothing because the damping ratio can be tuned independently of frequency.
Caveats & Gotchas
- • Approximations are accurate when InDeltaTime < 1 / InUndampedFrequency. A 10 Hz spring requires DeltaTime < 0.1s for reliable results — at 60fps this is fine, but large frames can cause instability.
- • InOutValueRate must be persisted between frames exactly like CriticallyDampedSmoothing — never reset it to zero mid-flight.
- • Setting InDampingRatio < 0 is undefined. Values slightly above 1.0 give the most pleasant camera-style easing; values of 0.5 create a visible bounce that suits physics-driven objects.
Signature
template< class T >
static void SpringDamper(T& InOutValue, T& InOutValueRate, const T& InTargetValue, const T& InTargetValueRate, const float InDeltaTime, const float InUndampedFrequency, const float InDampingRatio) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InOutValue | T& | The value to be smoothed. Modified in place. | — |
| InOutValueRate | T& | Rate of change of the value. Modified in place — persist between frames. | — |
| InTargetValue | const T& | The target to smooth towards. | — |
| InTargetValueRate | const T& | The target rate of change. | — |
| InDeltaTime | const float | Elapsed time since last update. | — |
| InUndampedFrequency | const float | Oscillation frequency in Hz when there is no damping. Higher values = stiffer spring. | — |
| InDampingRatio | const float | 1.0 = critical damping (no overshoot). <1 = underdamped (overshoot). >1 = overdamped (sluggish). | — |
Return Type
void Example
Springy camera offset with slight overshoot C++
// In header: FVector CameraOffset = FVector::ZeroVector; FVector CameraOffsetRate = FVector::ZeroVector;
FMath::SpringDamper(
CameraOffset, CameraOffsetRate,
TargetCameraOffset, FVector::ZeroVector,
DeltaTime,
3.f, // 3 Hz spring
0.7f // slightly underdamped for a natural bounce
); Tags
Version History
Introduced in: 4.26
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?