RealDocs

UKismetMathLibrary::Vector_Normal2D

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticBlueprintPure

Description

Normalizes only the X and Y components of the vector, setting Z to zero. Returns (0,0,0) if the 2D length is below Tolerance.

Caveats & Gotchas

  • Z is unconditionally set to zero in the output — even if the input has a non-zero Z. Use this only when you want a ground-plane direction, not a general 3D direction.
  • The safe-normalize tolerance is tested against the 2D (XY) squared length, not the full 3D length. A vector like (0,0,100) will fail the test and return zero despite being non-zero.

Signature

static UE_INL_API FVector Vector_Normal2D(FVector A, float Tolerance = 1.e-4f);

Parameters

Name Type Description Default
A FVector The vector to normalize in 2D (Z is ignored and zeroed).
Tolerance float Minimum squared XY length for normalization. Defaults to 1.e-4. 1.e-4f

Return Type

FVector

Example

Horizontal movement direction C++
FVector ToTarget = TargetActor->GetActorLocation() - GetActorLocation();
FVector HorizDir = UKismetMathLibrary::Vector_Normal2D(ToTarget);
AddMovementInput(HorizDir, 1.f);

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.