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:
Pull down from Root, search for Selector, and set the Name to Choose State node. Here, we will define three distinct states.
Pull Choose State and search for Sequence. Now, right-click, select Add Decorator, and find Blackboard.
Click on Blackboard and set Key Query to Is Not Set and Blackboard Key to TargetActor.
Right-click, click on Add Service, and find MoveBetweenRoutes.
Click on MoveBetweenRoutes and set Current Route to CurrentRoute.
Pull from Sequence...