Setting up the investigating tasks

With the decorator set, we can move on to creating some of the tasks we will use to cause the enemy to investigate the location of the sound. The first Action of our investigation sequence will be to move the enemy to the location of the sound. We have already done something very similar in the attack sequence. Drag a wire down from the Investigate Sound sequence and attach it to a Move To task node.

In the Details panel of the Move To node, change Blackboard Key to LocationOfSound. Now, drag a second wire down and attach it to a Wait node. Change Wait Time to 4 seconds and Random Deviation to 1 second. This will cause the enemy to move to the location of the sound that it heard and wait at that location for 3 to 5 seconds, looking for the player.

Once the enemy is finished waiting at the investigation location, we want to reset the Boolean key that contains the information that a sound was heard. We do this so that when a new sound is heard, the key can be set to true one more time, causing another investigation to occur. We have already created a custom task called ResetValueTask. We need another task that does a similar job but is capable of resetting a Boolean value.

Click on the New Task button at the top of the Behavior Tree, and then select the BTTask_BlueprintBase option from the drop-down menu that appears. Return to Content Browser and find the new task object, called BTTask_BlueprintBase_New, in the Enemy folder. Rename this object as ResetBoolTask. Double-click on ResetBoolTask to return to the task's tab. We will assemble sets of Blueprint logic to handle cases where we need to reset the variable telling the AI that a sound was heard. The Blueprint nodes that we will construct can be seen in the following screenshot:

Look at the My Blueprint panel and add two variables. Call the first variable Key and change its type to BlackboardKeySelector. Rename the second variable as Bool and change its type to Boolean. Finally, ensure that both of these variables have the Instance Editable box checked.

Now, let's add the behavior for the task. Add an Event Receive Execute trigger node to the Event Graph. Drag a wire out from the execution pin and attach a Set Blackboard Value as Bool node. Next, drag the Key variable onto the Key input pin. Then, drag the Bool variable onto the Value input pin. Finally, drag a wire from the output execution pin of the Set Blackboard Value as Bool node and attach it to a Finish Execute node. Check the box next to the Success input of this node.

In addition to handling the execution Event, we will also have to address what happens when the hearing sequence in the Behavior Tree is aborted by the higher priority execution of the attack sequence. Even if the hearing sequence is aborted while in progress, we still need to ensure that the HasHeardSound variable is reset. We can do this using Event Receive Abort.

Add an Event Receive Abort trigger node to the graph, and then attach it to another Set Blackboard Value as Bool node. As before, drag the Key variable onto the Key input pin and the Bool variable to the Value input pin. Finally, drag a wire from the output execution pin of the Set Blackboard Value as Bool node, and then attach it to a Finish Abort node. Save the task and return to EnemyBehavior.

Drag a wire down and place a ResetBoolTask task node to the right of the Wait node. Change the Key selection to HasHeardSound inside the Details panel of ResetBoolTask. You should also change Node Name to Reset Player Heard in order to be more specific about its functionality. The final sequence of tasks should look like this:

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

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