Making enemies hear and investigate sounds
Enemies that can only pursue players who walk directly in front of them can easily be avoided. To address this, we will take advantage of the PawnSensing component to have the enemy detect nearby sounds that the player makes. If the player makes a sound within the detection range of an enemy, then the enemy will walk to the location of that sound to investigate. If they catch the player in their sight, they will try to attack; otherwise, they will wait at the location of the sound for a moment before returning to their patrol.
Adding hearing to the Behavior Tree
We will add a sequence of tasks 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 has a lower priority on the Behavior Tree.
To have the enemy investigate the point where it heard a sound, we will need to create two keys within the blackboard. The HasHeardSound
key is of the Boolean type...