Chapter 8. Creating Patrol, Chase, and Attack AI

In this chapter, we will combine some of the components we used in the previous chapters, including AI Sense and other components, to have AI navigate. Then, we will add some randomness in the time-out time that will make the AI chase after the characters it detects. Now, in this chapter, we can create AI using Behavior Tree while utilizing other AI components. A combination of these components can create responsive and convincing AI behavior.

The goal of this chapter is to create an AI that will fire at you using Behavior Tree; this last AI component will benefit you because there is no perfect solution. So, understanding each of the available tools allows you to exploit the advantages of each component for your use in AI. These tools allow you to create AI that is responsive and convincing.

Creating a Blackboard

Blackboards define the local variable space for Behavior Trees. These Blackboards can also sync with other instances of the same Blackboard. Blackboards can be created first because you'll find yourself modifying them often until you discover everything you need for your Behavior Tree.

We will create our Blackboard data first and then supply it to our Behavior Tree. Now, let's start! Here are the steps:

  1. Right-click on the Content folder and create a new folder named AI.
  2. Now, right-click inside the folder and scroll down to find Artificial Intelligence; then, click on Blackboard. Let's name this EnemyData.
  3. We will open EnemyData and then create two object variables to be used by Behavior Tree. Name the first one TargetActor and the next one CurrentRoute.

    Note

    In case you're using Enumeration, you can define the enumeration the same way we will define actors for these objects.

  4. Click on TargetActor and select the Key Type option in the drop-down menu. Then, change the Base Class value to Actor. We want to do the same with CurrentRoute, as in the following screenshot:
    Creating a Blackboard

Behavior Tree is a tree of nodes whose structural diagram dictates the flow control, each leaf node representing the actual code for the AI to execute. This results in the AI making a sequence of decisions appropriate to the input it receives. To see a sample of what we will end up making today, here is how Behavior Tree looks in Unreal Engine 4:

Creating a Blackboard

There are many forms of state machines available in the world. Behavior Tree is a form of a tree with a subtree of nodes. It has composites that allow you flow control, resulting in the execution of leaves, which also have additional flow control. This level of control allows you to create deep Behavior Trees with a lot of control.

Let's begin to create our own and get a quick look of what to expect later in the course:

  1. We will right-click on EventGraph and scroll down to Artificial Intelligence. Now, let's click on Behavior Tree and name this EnemyAI.
  2. Open up EnemyAI, and you should see EnemyData populated in the ROOT node. If not, click on the ROOT node and set the Blackboard asset to EnemyData:
    Creating a Blackboard
..................Content has been hidden....................

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