Creating the logic

Now, we have all our components done. We configured our three custom nodes. Now, we just have to go back to our Behavior Tree. Then, we have to set up three states for the AI to be in. The first is Patrol, which is responsible for moving the AI to the next route. The second is Chase, which is responsible for moving the AI within radius of the player. The final state is Attack, and this state will fire and rotate the AI until Target is no longer within distance.

Now, let's open the EnemyAI Behavior Tree via the following steps:

  1. Pull down from Root, search for Selector, and set the Name to Choose State node. Here, we will define three distinct states.
  2. Pull Choose State and search for Sequence. Now, right-click, select Add Decorator ...

Get Unreal Engine 4 AI Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.