Version:

Setting up the AI Trigger Area

Setting up the AI Trigger Area

To set up the AI trigger area

  1. In the Asset Browser, navigate to \StarterGame\Slices. Drag Debug_manager.slice into the viewport.

    This slice manages some of the AI script’s functional behavior.
    [Image NOT FOUND]

  2. In the viewport, right-click the center of the maze and choose Create entity.

    This action creates an empty entity. In the Entity Inspector, name this entity AiTrigger.
    [Image NOT FOUND]
    [Image NOT FOUND]

  3. In the Entity Inspector, click Add Component. Under the Shape category, choose the Box Shape component. Tip
    To find the Box Shape component quickly, enter box in the Search bar.
    [Image NOT FOUND]

  4. In the Entity Inspector, in the Box Shape component, set the box’s Dimensions to X: 38, Y: 38, Z: 10.

    The AI is restricted to these dimensions, which approximate the size of the maze.
    [Image NOT FOUND]

  5. Use the Move tool to center the box so that it fits around the maze wall. Tip
    If the box does not appear in the viewport, click the ? icon in the upper-right corner of your viewport.
    [Image NOT FOUND]

  6. With the AiTrigger entity still selected, in the Entity Inspector, click Add Component. Under Scripting, choose Trigger Area.
    [Image NOT FOUND]

  7. In the Trigger Area component, under Tag Filters, click + next to Required tags.

    In the box labeled [0], enter PlayerCharacter.
    [Image NOT FOUND]

  8. In the Entity Inspector, click Add Component. Under Scripting, click Lua Script.

  9. In the Lua Script component, next to the Script box, click (...) to browse for a script file.
    [Image NOT FOUND]

    Navigate to \StarterGame\Scipts\AI. Select AISpawnTrigger.lua. Click OK.
    [Image NOT FOUND]

  10. In the Lua Script component, under Properties, in the AiSpawnGroup box, enter Group0.
    [Image NOT FOUND]

    When the player enters the trigger area defined by this entity’s shape, the AI scripts in the group are activated. When the player leaves the trigger area, the AI scripts are deactivated.

    Your Entity Inspector should look like the following image.
    [Image NOT FOUND]

  11. Press Ctrl+S to save your level.

Note
During gameplay, the player controller must start outside the maze trigger area and then enter it in order to activate the AI characters. If the game starts inside the trigger area, the player controller must leave and then reenter to trigger the AI.

Next: Defining the AI Navigation Area