UBlueprintSpringMathLibrary::VelocitySpringCharacterUpdate
#include "Kismet/BlueprintSpringMathLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Advances a character's position toward a target velocity using a velocity spring that tracks an intermediate velocity moving at a capped maximum acceleration. Unlike SpringCharacterUpdate, larger jumps in TargetVelocity take proportionally longer to reach because acceleration is clamped by MaxAcceleration.
Caveats & Gotchas
- • Marked UE_EXPERIMENTAL(5.7, "SpringMath is experimental") — behaviour and defaults may change in later engine versions.
- • InOutVelocity, InOutVelocityIntermediate, and InOutAcceleration are all caller-owned state that must persist between calls — resetting any of them to zero mid-sequence produces a visible pop in motion.
- • MaxAcceleration defaults to 1.0, which is very low for world-unit velocities (cm/s) — leaving it at the default typically makes the character feel like it never reaches TargetVelocity; tune it to the scale of your movement speeds.
Signature
static void VelocitySpringCharacterUpdate(UPARAM(ref) FVector& InOutPosition, UPARAM(ref) FVector& InOutVelocity, UPARAM(ref) FVector& InOutVelocityIntermediate, UPARAM(ref) FVector& InOutAcceleration, const FVector& TargetVelocity, float DeltaTime, float SmoothingTime = 0.2f, float MaxAcceleration = 1.0f); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InOutPosition | FVector& | The position of the character; updated in place each call. | — |
| InOutVelocity | FVector& | The velocity of the character. Must be stored and persisted by the caller between calls, usually starting at zero. | — |
| InOutVelocityIntermediate | FVector& | The intermediate target velocity of the character. Must be stored and persisted by the caller between calls, usually starting at zero. | — |
| InOutAcceleration | FVector& | The acceleration of the character. Must be stored and persisted by the caller between calls, usually starting at zero. | — |
| TargetVelocity | const FVector& | The target velocity of the character. | — |
| DeltaTime | float | The delta time to tick the character. | — |
| SmoothingTime | float | The time over which to smooth velocity; it takes roughly this long for the character to reach the target velocity. | 0.2f |
| MaxAcceleration | float | Caps the acceleration the intermediate velocity can apply each frame. A very large value makes this behave like SpringCharacterUpdate. | 1.0f |
Return Type
void Example
Advance a character position with a clamped-acceleration velocity spring C++
FVector Position = GetActorLocation();
FVector Velocity = FVector::ZeroVector;
FVector VelocityIntermediate = FVector::ZeroVector;
FVector Acceleration = FVector::ZeroVector;
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
UBlueprintSpringMathLibrary::VelocitySpringCharacterUpdate(
Position, Velocity, VelocityIntermediate, Acceleration,
DesiredVelocity, DeltaTime, 0.25f, 800.f);
SetActorLocation(Position);
} Tags
Version History
Introduced in: 5.7
| Version | Status | Notes |
|---|---|---|
| 5.7 | experimental | SpringMath is experimental. |
Feedback
Was this helpful?