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, and find Blackboard.
  3. Click on Blackboard and set Key Query to Is Not Set and Blackboard Key to TargetActor.
  4. Right-click, click on Add Service, and find MoveBetweenRoutes.
  5. Click on MoveBetweenRoutes and set Current Route to CurrentRoute.
  6. Pull from Sequence and search for MoveTo. Now, set MoveTo to CurrentRoute:
    Creating the logic
  7. Pull Choose State and search for Sequence. Now, right-click and select Add Decorator to find Blackboard.
  8. Click on Blackboard and set Key Query to Is Set and Blackboard Key to TargetActor.
  9. Right-click and select Add Decorator; then, search for Is At Location.
  10. 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.
  11. Pull from Sequence and search for Move. Click on Move and set MoveTo to TargetActor.
  12. Right-click on the MoveTo node, select Add Decorator, and search for ChaseTime.
  13. Click on ChaseTime and set Current Target to TargetActor and Chase Duration to 3.0:
    Creating the logic
  14. Pull from Choose State and search for Sequence.
  15. Right-click, select Add Decorator, and search for Blackboard. Click on Blackboard and set Key Query to Is Set and Blackboard Key to TargetActor.
  16. 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.
  17. Pull from Sequence and search for Attack at Mid Range:
    Creating the logic

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!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset