In this lesson, you will learn how to refine your Environmental Query System (EQS) results by filtering spatial points based on their physical distance from an actor and their line-of-sight visibility.
The Logic of Spatial Filtering
When an AI agent searches for a tactical position, the EQS generator might return hundreds of potential points. To make the AI act intelligently, we must discard points that are too far away or blocked by walls. We use Tests within the EQS editor to evaluate these candidates mathematically.
Distance Tests
The Distance Test calculates the magnitude between your generated points and a target (usually the Player or an Objective). You define this in the Test Details panel by setting the Test Purpose to Score Only or Filter.
- Distance To: Choose
DistanceToItem(distance to the generated point) orDistanceToContext(distance to the target actor). - Normalization: Distance is usually normalized to a
0-1range based on yourMinimumandMaximumthresholds. Points outside these bounds are culled, while points within are scored—closer points typically receive a higher score if you set theScoring EquationtoInverse Linear.
Trace Tests (Line-of-Sight)
Even if a point is close, it might be behind a solid pillar. The Trace Test performs a raycast from the AI's "Context" (usually their eyes) to the potential location.
- Trace Channel: Set this to
VisibilityorCamerato respect your collision geometry. - Test Purpose: Set this to
Filter. If the line-of-sight is blocked, the test returnsfalse, effectively removing that point from the AI's list of viable locations.
Implementing in the EQS Editor
- Right-click your Query and select Add Test > Distance.
- Set the
Distance TypetoDistanceToContextto evaluate proximity to the player. - Right-click again and add Add Test > Trace.
- Ensure
Trace Channelis configured correctly to hit walls. - In the
Tracetest settings, ensureVisibilityis checked forVisibleorNot Visibledepending on whether you want the AI to hide or seek.
Key Takeaway: By combining Distance and Trace tests, you transform raw spatial data into intelligent tactical choices, ensuring your AI only selects spots that are both physically accessible and strategically viable.