RealDocs

AActor::GetDotProductTo

function Engine Blueprint Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: UFUNCTIONBlueprintCallableconst

Description

Returns the dot product between this actor's forward vector and the normalized direction to OtherActor. Values near 1.0 mean OtherActor is directly in front; near -1.0 means directly behind.

Caveats & Gotchas

  • Returns -2.0 on failure (e.g., if OtherActor is null or has no valid location) and 0.0 if both actors are at the exact same location — check for -2.0 before using the result.
  • Uses 3D vectors including Z, so an actor directly overhead will return a low dot product even if it's in front horizontally. Use GetHorizontalDotProductTo for ground-plane facing checks.

Signature

ENGINE_API float GetDotProductTo(const AActor* OtherActor) const;

Parameters

Name Type Description Default
OtherActor const AActor* The other actor to compute the dot product toward.

Return Type

float

Example

Check if target is in front of this actor C++
float Dot = MyActor->GetDotProductTo(TargetActor);
if (Dot != -2.f && Dot > 0.7f) // roughly within 45 degrees
{
    UE_LOG(LogTemp, Log, TEXT("Target is in front"));
}

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.