FVector::DotProduct
#include "Math/Vector.h"
Access: public
Specifiers: static
Description
Computes the dot product of two vectors: `A.X*B.X + A.Y*B.Y + A.Z*B.Z`. If both vectors are unit (normalized), the result is the cosine of the angle between them: 1.0 = same direction, 0.0 = perpendicular, -1.0 = opposite.
Signature
static double DotProduct(const FVector& A, const FVector& B) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | const FVector& | First vector (should be normalized for directional checks). | — |
| B | const FVector& | Second vector (should be normalized for directional checks). | — |
Return Type
double Caveats & Gotchas
- • Inputs must be normalized for the result to equal the cosine of the angle between them.
- • Can also be written as `A | B` using the operator overload.
Example
Checking if an actor is in front of another C++
FVector Forward = GetActorForwardVector(); // Already normalized
FVector ToTarget = (Target->GetActorLocation() - GetActorLocation()).GetSafeNormal();
float Dot = FVector::DotProduct(Forward, ToTarget);
// Dot > 0: target is in front
// Dot < 0: target is behind
// Dot >= 0.7f: within ~45 degrees of forward Tags
Version History
Introduced in: 1.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?