UKismetAnimationLibrary::CalculateDirection
#include "KismetAnimationLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the signed angle in degrees between Velocity and the forward vector of BaseRotation, in the range [-180, 180]. Commonly used to drive directional blendspaces.
Caveats & Gotchas
- • Only the yaw component of BaseRotation and the horizontal plane of Velocity are effectively used, so vertical movement (e.g. falling straight down) does not skew the result in unexpected ways but also isn't reflected in it.
- • If Velocity is near-zero, the direction becomes noisy since a tiny vector's angle relative to forward is poorly defined; feed this from a smoothed/consistent velocity source for stable blendspace results.
Signature
static float CalculateDirection(const FVector& Velocity, const FRotator& BaseRotation) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Velocity | const FVector& | The velocity to measure, relative to BaseRotation. | — |
| BaseRotation | const FRotator& | The base rotation, typically the owning pawn's actor rotation. | — |
Return Type
float Example
Drive a directional blendspace from movement velocity C++
float Direction = UKismetAnimationLibrary::CalculateDirection(GetOwningComponent()->GetOwner()->GetVelocity(), GetOwningComponent()->GetOwner()->GetActorRotation());
// Feed Direction into a 1D or 2D blendspace input in the anim graph Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?