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 and search for MoveTo. Now, set MoveTo to CurrentRoute:
Pull Choose State and search for Sequence. Now, right-click and select Add Decorator to find Blackboard.
Click on Blackboard and set Key Query to Is Set and Blackboard Key to TargetActor.
Right-click and select Add Decorator; then, search for Is At Location.
Click on Is At Location and set Acceptable Radius to 600.0, Inverse Condition to True, and Blackboard Key to TargetActor. Inverse Condition will return True if we are outside the Acceptable Radius value.
Pull from Sequence and search for Move. Click on Move and set MoveTo to TargetActor.
Right-click on the MoveTo node, select Add Decorator, and search for ChaseTime.
Click onChaseTime and set Current Target to TargetActor and Chase Duration to 3.0:
Pull from Choose State and search for Sequence.
Right-click, select Add Decorator, and search for Blackboard. Click on Blackboard and set Key Query to Is Set and Blackboard Key to TargetActor.
Right-click, select Add Decorator, and search for Is At Location. Click on Is At Location and set Acceptable Radius to 599.99 and Blackboard Key to TargetActor.
Pull fromSequence and search for Attack at Mid Range:
Now, with all these nodes here, you have a complete enemy AI, which you can now fight and take on for yourself! Congratulations on coming this far!