UAnimInstance::CalculateDirection
#include "Animation/AnimInstance.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableENGINE_API
Description
Computes the angle in degrees (–180 to 180) between a velocity vector and a base rotation, projected onto the horizontal plane. Commonly used in locomotion blend spaces to drive directional movement animations (strafing, backpedaling).
Caveats & Gotchas
- • Returns 0.0 when the velocity vector is near-zero length, which can cause blend spaces to snap to the forward idle pose. Guard against this by checking velocity magnitude before calling.
- • The calculation is 2D only — it projects onto the XY plane and ignores the Z component. Characters moving on steep slopes or flying will get inaccurate direction values unless you zero out the Z velocity first.
Signature
UFUNCTION(BlueprintCallable, Category="Animation", meta=(BlueprintThreadSafe))
ENGINE_API float CalculateDirection(const FVector& Velocity, const FRotator& BaseRotation) const; Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Velocity | const FVector& | The velocity vector to compute the direction from, typically the character's movement velocity. | — |
| BaseRotation | const FRotator& | The reference rotation to measure the direction against, typically the character's actor rotation or control rotation. | — |
Return Type
float Example
Drive a locomotion blend space direction variable C++
void UMyAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
if (APawn* Pawn = TryGetPawnOwner())
{
FVector Velocity = Pawn->GetVelocity();
FRotator Rotation = Pawn->GetActorRotation();
Direction = CalculateDirection(Velocity, Rotation);
Speed = Velocity.Size();
}
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?