The dot product of two vectors tells you how much they point in the same direction. For two unit vectors A and B, the dot product equals the cosine of the angle between them:

If both vectors are normalized (length 1), this simplifies to:

The result ranges from 1 (same direction) through 0 (perpendicular) to -1 (opposite directions).

In Game Development

Dot product is everywhere in game math:

  • Cone detection — check if an object is within a certain angle of the camera’s forward vector. If DotProduct(CameraForward, DirectionToTarget) > cos(threshold), the target is inside the cone. This is how the NGInteractionSystem selects the best interactable.
  • Facing checks — is an enemy looking at the player? Dot their forward vector with the direction to the player.
  • Lighting — diffuse lighting is just the dot product of the surface normal and the light direction.

In Unreal Engine

float Dot = FVector::DotProduct(A, B);
float Angle = FMath::RadiansToDegrees(FMath::Acos(Dot));

FVector::DotProduct takes two FVectors and returns a float. To get the actual angle, pass the result through acos — but often you can skip that and compare the dot product directly against a precomputed cosine threshold, which avoids the expensive acos call.