Making the AI go to a location when the player enters a proximity trigger
In this recipe, we will demonstrate how you may be able to give a basic Goto command to an AI (Artificial Intelligence) when the player enters a trigger.
Getting ready
Open Sandbox and then open My_Level.cry
Complete the How to beam the player to a tag point from a trigger recipe to learn how to place the proximity triggers
Then place down a new Grunt
How to do it...
First, place down a proximity trigger and a solid with the same dimensions and properties as the previous recipe.
Then place down an AI tag location within that same trigger area.
Next, create a new Flow Graph from the trigger area called AI_Goto.
Within the Flow Graph, create the following logic:
From the perspective viewport of the editor, select the ProximityTrigger and the TagPoint
Add Selected Entities to the Proximity Trigger Flow Graph
Add Node | AI | AIGoto
Select a Grunt from the perspective viewport.
Back in the Flow Graph, right-click AIGoto | Assign Selected Entity.
Link Enter output from the ProximityTrigger to the Sync input of AIGoto.
Link pos output from the TagPoint to the pos input of AIGoto.
With that logic now set up, the AI should now attempt to go to that tag point (unless its behavior is interrupted by perceiving the player).
How it works...
With the AIGoto node, this trigger is a nudge to the AI's behavior tree to signal a basic command for the AI to go to a specific location. Unless the AI's behaviour is not currently busy with other tasks, the AI will proceed to the defined location.
There's more...
Here is an extra Flow Graph node you might want to try as well.
AIGotoEx
An extended version of the AIGoto node is the AIGotoEx. This node allows the designer to forcefully command the AI to go to a particular location regardless of the current condition of its state. This is a key node to use if the designer wants to force the AI to retreat for example.