Behavior
Status setup
Now that we know, perception is working. We need to get our status system set up. In the newly created AI controller, you will find Status_0 and GetAllStatusOptions functions Duplicate the Status_0 function twice and name it Status_Alert and Status_SearchForTargets.
In Status_SearchForTargets. Set float value in select float node to 2 on A.
Call function "Get Targets Heard In memory"> "Arraylength">"MoreThan0" and connect it to select node

Select gameplay tag for S_Status Structure

For Status_Alert, add "PriorityTarget">"IsValid" and connect to select float. Select the gameplay tag. Set float value to 3 for A on select float node.

Now let's go back to Get all Status options function
And add calls to those functions and connect them to make array function.

Behavior tree setup
In a controller, select the Behavior tree with your system's name.

In the Behavior tree asset, select Blackboard with your system's name.

Fire weapon service
With robust weapon systems, you would not need to do a lot here. But since we have simple line trace instead of our weapon, we need to make sure AI will not rapid-fire.
Create a new Behavior tree service and name it BTService_Fire In this service, overwrite Receive Activation AI and Receive Deactivation AI
If you are not using the character we set up, you will have to figure this part out yourself. For those who were following along, create a cast for your character and save the result in a variable like this:

Next, create a timer event, save its handle, and create the event of it just like this:

Time float would regulate the time between shots. On Event, Receive Deactivation AI, grab the Timer handle, and deactivate the timer.

Tree
In the Behavior tree asset, add a selector node, and connect it to the root. Add two sequence nodes and add the BTD_GameplayTag decorator on top of each sequence.

In Decorator properties, select tag AI.Status.Alert for left decorator and AI.Status.SearchingForEnemy

For the left sequence, add the "Fire" service

Select Decorator aborts as "self". Click on decorator and find this
Otherwise AI will keep going in direction of gunshot even after spotted player
In addition, add default focus service and select Active target key select then connect "move to" node to left sequence. For the right sequence, connect "move to" and select the sound location as a key.

Testing
As expected AI:
It will also react to damage if you have a health system.
Last updated