Course contentsShow
← Unreal Engine Game Development
Lesson 433 of 8806. AI, Navigation, and Decision MakingFree lesson

Using Dot Product for Tactical Orientation

Students will utilize dot product tests to evaluate spatial points based on their directional alignment relative to the AI's facing.

Mastering Tactical Orientation with Dot Product

In this lesson, you’ll learn how to use the Dot Product to allow your AI to mathematically evaluate if a potential movement destination is "in front of" or "behind" its current orientation for tactical positioning.

The Geometry of Decision Making

The Dot Product of two normalized vectors provides a single scalar value representing the cosine of the angle between them. When we compare an AI's GetActorForwardVector with a DirectionToTarget vector (the vector from the AI to a potential location), the result helps us categorize spatial points:

  • Result ≈ 1.0: The target is directly in front.
  • Result ≈ 0.0: The target is to the side (orthogonal).
  • Result ≈ -1.0: The target is directly behind the AI.

By using this in an Environment Query (EQS), you can prioritize tactical movement. For example, if you want your AI to maintain line-of-sight while retreating, you would filter for points where the dot product is negative, signaling that these locations are behind the AI's current facing.

Implementation Example

To implement this in a Blueprint-based Test or a custom Service, you calculate the normalized direction and compare it against the forward vector:

// Logic inside a custom Test or Service
FVector Forward = AIController->GetPawn()->GetActorForwardVector();
FVector DirectionToPoint = (PointLocation - AILocation).GetSafeNormal();

float DotResult = FVector::DotProduct(Forward, DirectionToPoint);

// Tactical check: Is the point generally in front of the AI?
bool bIsTacticallySound = (DotResult > 0.5f);

By applying this logic, you move away from simple distance-based decision-making. Instead of just picking the "closest" cover spot, your AI can now prefer "flanking" spots (Dot Product near 0) or "retreat" spots (Dot Product near -1), creating much more believable and strategic behavior during combat encounters.

Integrating this into your EQS allows for complex, context-aware navigation without needing to hard-code specific pathing scenarios. The AI essentially performs a "spatial look-ahead" based on its own physical orientation in the world.

Key Takeaway: The Dot Product transforms raw spatial coordinates into meaningful tactical data, allowing your AI to classify positions as strategically favorable based on its current forward orientation.