RealDocs

FMath::GetDotDistance

function Core Since 4.0
#include "Math/UnrealMathUtility.h"
Access: public Specifiers: static

Description

Computes the dot-distance of a direction vector relative to a coordinate system, returning the cosine of azimuth and sine of elevation. Returns true if the direction is in front of the AxisX plane.

Caveats & Gotchas

  • OutDotDist.X is the dot of Direction with AxisX projected onto the AxisX/AxisZ plane, not a raw dot product. Its sign indicates left (-) vs right (+) of the reference forward axis, not front/back — front/back is the function's return value.
  • All input vectors should be unit-length. Passing non-normalised vectors will produce incorrect angular distances without any assertion or error.

Signature

static CORE_API bool GetDotDistance(FVector2D &OutDotDist, const FVector &Direction, const FVector &AxisX, const FVector &AxisY, const FVector &AxisZ)

Parameters

Name Type Description Default
OutDotDist FVector2D& Output: X = cos(Azimuth) relative to the AxisX/AxisZ plane; Y = sin(Elevation) relative to the AxisX/AxisY plane.
Direction const FVector& The direction toward the target.
AxisX const FVector& Forward axis of the reference coordinate system.
AxisY const FVector& Right axis of the reference coordinate system.
AxisZ const FVector& Up axis of the reference coordinate system.

Return Type

bool

Example

Check if an enemy is in front of and to the right of the camera C++
FVector CamFwd, CamRight, CamUp;
CameraComponent->GetForwardVector().ToDirectionAndLength(CamFwd, (float&)0);
CamRight = CameraComponent->GetRightVector();
CamUp    = CameraComponent->GetUpVector();

FVector2D DotDist;
bool bInFront = FMath::GetDotDistance(
    DotDist,
    (EnemyLocation - CameraComponent->GetComponentLocation()).GetSafeNormal(),
    CamFwd, CamRight, CamUp
);
if (bInFront && DotDist.X > 0.f)
{
    // Enemy is in front and to the right
}

Tags

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.