RealDocs

UKismetAnimationLibrary::K2_CalculateVelocityFromPositionHistory

function AnimGraphRuntime Blueprint Since 4.0
#include "KismetAnimationLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintCallable

Description

Tracks a position over successive calls and returns a smoothed scalar velocity magnitude, optionally normalized into a 0-1 range. Requires a persistent FPositionHistory variable to accumulate samples across calls.

Caveats & Gotchas

  • • History must be backed by a variable that persists between calls (a member variable in C++, or a Blueprint variable passed by ref) — passing a temporary or freshly-constructed FPositionHistory every call means velocity is always computed from a single sample and produces near-zero or garbage results.
  • • This is BlueprintCallable, not BlueprintPure — it has side effects (mutating History) each time it's called, so calling it multiple times per frame accumulates multiple samples and will skew the smoothing.
  • • When VelocityMin and VelocityMax are both 0.0, normalization is disabled and the function returns the raw velocity magnitude instead of a 0-1 value.

Signature

static float K2_CalculateVelocityFromPositionHistory(float DeltaSeconds, FVector Position, UPARAM(ref) FPositionHistory& History, int32 NumberOfSamples, float VelocityMin, float VelocityMax)

Parameters

Name Type Description Default
DeltaSeconds float Time passed in seconds since the last call. —
Position FVector The position to track over time. —
History FPositionHistory& Persistent storage for the position history; must be a variable that stays alive between calls. —
NumberOfSamples int32 Number of samples to retain for the history — higher values smooth the velocity result more. 16
VelocityMin float Minimum velocity for normalization; if both min and max are 0, normalization is disabled. 0.f
VelocityMax float Maximum velocity for normalization; if both min and max are 0, normalization is disabled. 128.f

Return Type

float

Example

Track smoothed velocity for a moving actor C++
// FPositionHistory PositionHistory; // member variable, persists across ticks
const float Velocity = UKismetAnimationLibrary::K2_CalculateVelocityFromPositionHistory(
    DeltaSeconds, GetActorLocation(), PositionHistory, 16, 0.0f, 128.0f);

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable —

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.