12. Creating the FindHidingSpot EQS

For this step you'll be creating a much more involved Environment Query. It's going to create a grid of points, projected onto the NavMesh, then run a series of tests to figure out the best place to hide. Some of the tests will simply cull out completely unsatisfactory locations, such as those that are visible to the Player's Character (Trace), others will weight the potential hiding spots based on if they are reachable on the NavMesh (PathFinding) or how much a point is in front of the Player's Character (Dot Product).

Just a quick reminder:

  • A Generator creates Items in relation to a Context

  • Items are used in Tests often in relation to a Context (how far is Item X from Context Y)

  • Items are culled or scored based on the results of Tests

Steps

  1. To start, Double-click the FindHidingSpot Environment Query asset in the Content Browser.

    findHide.png

  2. Create Simple Grid Generator and connect it to the Root node

    simpleGrid.png

  3. Select the Simple Grid Generator and in the Details Panel set the following Properties:

    gridProp.png

    • Grid Size = 2000.0

    • Space Between = 150.0

    • Navigation Filer = RecastFilter_UseDefaultArea

    • Project Down = 2048.0

    • Post Projection Vertical Offset = 32.0

    These settings for the Grid Generator will create a sizable, but manageable, number of Items for the Query to test against. The Project Down, Project Up, and Post Projection Vertical Offset properties are particularly useful to change if you have an AI that needs to find something above or below them.

  4. Add 2 Distance Tests by Right-clicking the Simple Grid node and selecting Tests arrow_button.png Distance

    addDistance.png

  5. Select the first one and in the Details panel adjust the following properties:

    distanceProps.png

    • Distance To = Player Context

    • Test Purpose = Score Only

    This Distance test is meant to give Items further from the Player a higher Score.

  6. Select the second one and in the Details Panel adjust the following Properties:

    distanceProps2.png

    • Test Purpose = Score Only

    • Scoring Equation = Inverse Linear

    • Scoring Factor = 2.0

    This Distance test is meant to give Items closer to the AI a higher Score, and this test carries more weight than the previous Distance Test meaning it will favor closer to the AI but still select away from the Player.

  7. Add 2 Trace Tests by Right-clicking the Simple Grid node and selecting Tests arrow_button.png Trace

    addTrace.png

  8. Select the one of the Trace tests and in the Details panel change Context to PlayerContext (the Context created earlier in this Quick Start):

    traceProps.png

    Here we remove any Item that the Player Pawn or AI pawn has line of sight to. Also, you may be concerned that this test comes after a bunch of Distance tests, but it's ok, as the Environment Query runs Trace tests first regardless of order here. Also, the other Trace requires no additional setup.

  9. Add a Dot test by Right-clicking the Simple Grid node and selecting Tests arrow_button.png Dot

    addDot.png

  10. Select the Dot test and in the Details panel adjust the following properties:

    dotProps.png

    • Line A - Rotation = PlayerContext

    • Line B - Line From = PlayerContext

    • Absolute Value = True

    • Test Purpose = Score Only

    • Scoring Factor = -1.0

    Here things get tricky, at the high level, this is saying "Favor Items that are to the sides of the Player Pawn," but how it works is a bit odd. A Dot Product function will return how alike two vectors are on a scale of 1.0 (perfectly the same) to -1.0 (completely opposite). So if we get the Absolute Value of the Dot Product between the rotation vector of the Player and the vector from the Player to the Item we'll favor points in front of and behind the Player. But if we set the Scoring Factor to -1.0, then we favor to the sides of the Player.

  11. Add a PathFinding test by Right-clicking the Simple Grid node and selecting Tests arrow_button.png PathFinding

    addPath.png

  12. Select the PathFinding test and in the Details panel adjust Test Purpose to Score Only:

    pathProps.png

    That's it for the editing! The final Environment Query will look similar to this:

    final.png