Adding hearing to the Behavior Tree

The first step to introducing any additional functionality to the AI is figuring out where that logic will fit within the Behavior Tree. Go to Content Browser, open the Enemy folder, and open EnemyBehavior. We are contemplating adding a sequence of Events that occur when the enemy hears a sound. We want the enemy to continue attacking the player once they see them, so investigating a sound should constitute a lower priority on the Behavior Tree. Move the Attack Player sequence and all of its task nodes further to the left in the Behavior Tree, leaving room between Attack Player and Move to Patrol. This is where we will add our hearing sequence. Drag a wire down from the Selector node and attach it to a new Sequence node. Rename this node as Investigate Sound.

To have an enemy investigate the point where it heard a sound, we will need to keep track of two bits of information. The first is whether or not a sound has been heard. The second is the location that the sound came from, and hence the location that the enemy AI should investigate. We will create two keys within the Blackboard to store this information. Click on the Blackboard tab of EnemyBehavior.

Next, click on the New Key button and choose to make a key of the Vector type. Call this key LocationOfSound. Click on New Key a second time, this time making it a Bool type, and call it HasHeardSound. With the keys created, click on the Behavior Tree tab to return to the Behavior Tree view.

Before we begin creating tasks, we can set up the condition that will determine when the investigation of a sound should take place. To do this, right-click on the Investigate Sound sequence node, hover over Add Decorator, and click on the Blackboard option. Now, click on the blue decorator and look at the Details panel. Under Flow Control, change the Observer aborts value to Lower Priority. This will ensure that the investigation can begin as soon as a sound is heard, even if the enemy is midway through a patrol task, by aborting the lower priority tasks. Now, look at the Blackboard category and change Blackboard Key to HasHeardSound. Combined with Key Query being Is Set, this will allow the Investigate Sound sequence tasks to fire only when a sound has actually been heard. Finally, name the node something representative of its Function. I suggest Heard Sound?:

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

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