UKismetMathLibrary::Quat_EnforceShortestArcWith
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Modifies quaternion A in-place so that the rotation delta between A and B takes the shortest possible arc (≤180°). Essential for smooth interpolation when two quaternions may represent the same orientation via different winding paths.
Caveats & Gotchas
- • This modifies A in-place — call before any SLERP or interpolation that needs smooth, non-flipping results. Forgetting this step is a common cause of sudden 360° flips during animation blending.
- • The function negates A if the dot product A·B is negative. If you later compare A to its pre-call value, expect the signs of all four components to be flipped even though the represented rotation is geometrically identical.
Signature
static UE_INL_API void Quat_EnforceShortestArcWith(UPARAM(ref) FQuat& A, const FQuat& B); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FQuat& | The quaternion to modify in-place so it represents the shortest arc to B. | — |
| B | const FQuat& | The reference quaternion to measure the arc against. | — |
Return Type
void Example
Prevent flip during quaternion SLERP C++
FQuat CurrentQuat = GetActorQuat();
FQuat TargetQuat = TargetActor->GetActorQuat();
// Ensure we interpolate the short way around
UKismetMathLibrary::Quat_EnforceShortestArcWith(CurrentQuat, TargetQuat);
FQuat Result = FQuat::Slerp(CurrentQuat, TargetQuat, 0.1f);
SetActorRotation(Result.Rotator()); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?