UKismetMathLibrary::VectorSpringInterp
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Interpolates a vector using a damped spring model, producing natural overshoot and oscillation. Maintains velocity state between frames via FVectorSpringState.
Caveats & Gotchas
- • SpringState must be stored as a persistent member variable — one per spring instance. Sharing state across multiple calls or reinitializing it every frame will corrupt the velocity accumulation and produce jitter or no movement.
- • Set TargetVelocityAmount to 0 when using this to smooth sensor or animation data. A value of 1 causes the spring to anticipate the target's motion, which looks great for tracking a moving target but amplifies noise in fast-changing input.
Signature
static ENGINE_API FVector VectorSpringInterp(FVector Current, FVector Target, UPARAM(ref) FVectorSpringState& SpringState, float Stiffness, float CriticalDampingFactor, float DeltaTime, float Mass = 1.f, float TargetVelocityAmount = 1.f, bool bClamp = false, FVector MinValue = FVector(-1.f), FVector MaxValue = FVector(1.f), bool bInitializeFromTarget = false); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Current | FVector | The current value this frame. | — |
| Target | FVector | The target value to spring toward. | — |
| SpringState | UPARAM(ref) FVectorSpringState& | Persistent state struct (velocity, etc.) — must be a unique variable per spring instance. | — |
| Stiffness | float | Spring stiffness. Higher values oscillate faster. | — |
| CriticalDampingFactor | float | Damping ratio. 0 = no damping (oscillates forever), 1 = critically damped (no oscillation), >1 = overdamped (slow return). | — |
| DeltaTime | float | Time elapsed since last call. | — |
| Mass | float | Simulated mass. Higher mass means slower acceleration. | 1.f |
| TargetVelocityAmount | float | 0–1 blend of how much the target's velocity influences the spring. Set to 0 when smoothing noisy data. | 1.f |
| bClamp | bool | When true, output is clamped to [MinValue, MaxValue] per-axis and velocity is cancelled at limits. | false |
| MinValue | FVector | Per-axis minimum output clamp (used when bClamp=true). | FVector(-1.f) |
| MaxValue | FVector | Per-axis maximum output clamp (used when bClamp=true). | FVector(1.f) |
| bInitializeFromTarget | bool | If true, initializes Current from Target on the first update to avoid a large initial impulse. | false |
Return Type
FVector Example
Spring-follow a target location C++
// Header:
FVectorSpringState SpringState;
// Tick:
FVector NewPos = UKismetMathLibrary::VectorSpringInterp(
GetActorLocation(), TargetActor->GetActorLocation(),
SpringState, 100.f, 0.7f, DeltaTime);
SetActorLocation(NewPos); Tags
Version History
Introduced in: 4.26
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?