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

Implementing Dynamic Flanking Maneuvers

Learners will design an EQS query to find optimal flanking positions that maintain line-of-sight while minimizing exposure to the player.

In this lesson, you will learn how to design an Environmental Query System (EQS) that calculates optimal flanking positions by balancing line-of-sight against tactical exposure.

The Logic of a Flank

To perform a successful flank, your AI needs to move to a location that provides a clear shot at the player while remaining "out of the way" of their primary focus. We achieve this by combining two primary EQS tests: Trace and Dot Product.

  1. The Generator: Use a Points: Circle or Points: Donut generator centered on the Player’s current location. This gives the AI a pool of potential candidates surrounding the target.
  2. The Trace Test: Add a Trace test to ensure the AI has Line of Sight to the player. However, set this test to score higher for spots that are not directly in front of the player.
  3. The Dot Product Test: This is the heart of flanking. We want to position the AI at a 90-degree angle relative to the player’s "Forward" vector. By using the Dot Product test, we compare the vector (Player Location -> AI Candidate) with the (Player Actor -> Forward Vector).

Configuring the Tactical Weight

To ensure the AI doesn't pick a spot that is too exposed, use the Scoring settings within the tests:

  • Distance Test: Weight this to prefer a medium range (e.g., 800–1200 units) to avoid being too close.
  • Dot Product Test: Set the Test Purpose to Score. By aiming for a Dot Product value near 0.0 (which represents perpendicularity), the AI naturally chooses positions to the side of the player rather than directly in front.
// Logic concept for the Dot Product test
// 1. Calculate direction: CandidatePoint - PlayerLocation
// 2. Normalize that vector
// 3. Dot Product with PlayerActor->GetActorForwardVector()
// 4. Result near 0.0 = Successful Flank!

By normalizing these scores, the EQS will return the point that best satisfies being "at the side" and "in view." This creates a fluid, organic movement pattern where the AI constantly shifts to maintain a superior angle as the player moves.

Key Takeaway: Dynamic flanking is achieved by weighting the Dot Product test to prioritize perpendicular vectors relative to the player's forward orientation, ensuring the AI maintains visibility while stepping out of the player's direct line of fire.