AI systems using Unreal Engine 4: part 5

Jul 02, 2020 at 10:00 am by nemirc

Hello again and welcome. This time, I will explain the patrolling branches of my AI. For my patrolling branches I have 2 options: alert level is 2 and alert is greater or equal to 3. Basically, what this means is if the stalker heard the player, or barely saw the player enough to become alert (alert level 2), or if the stalker saw the player enough to get into an aggressive state (alert level 3). Another thing I need to remind you is that, no matter how many times the stalker hears the player, its alert level will never go above 2.

Let's pick the first branch. This branch divides into two branches that tell the stalker to do one thing or another depending on the stimulus type. The first branch happens if the stimulus was 1 (if the stalker heard the player, or an object) and the second branch happens if the stimulus was 2 (if the stalker saw the player). 

In part 3, I had mentioned I was also outputting a "stimulus type" variable from the AIPerception component. This is why I was using it. The idea is to have different patrol patterns depending on the stimulus.

Checking the first branch: the stalker goes to the sound source location and then gets into the patrolling state. The branch has a Sequence node, and you know this means every Service (from left to right) will run after the previous one is finished. What this group of nodes does is this: it makes the stalker pick a random point so it "patrols" around its location, to simulate the "you must be somewhere around this area" situation.

The second and third Services are built-in Services, but the first one is custom-made. It picks a random location within 800 units from the stalker, and then "ends" the Service using the Finish Execute node so the Sequence can move on to the next Service. One thing worth noting is that the picked location should be farther than 500 units from the stalker, and if the condition is not met a new location is picked. The reason I did this was to avoid a situation where the stalker just gives a couple of steps from its current position.

The other branch is similar, except that it will pick a location around the player. The stalker also picks a random location, this time around the player, and moves to that location.

There are a couple of differences, though. The first one is that the stalker picks a location within 600 units of the player, and then the random location is farther than 200 units. This narrows the walkable area around the player, and, in theory, it should make the player feel more anxious as the stalker is walking really close.
In case the perceived stimulus was 3, meaning that the stalker saw the player and went into full aggressive state, the branch is similar, except that this one has a cool down (this cool down is currently just a test, and it may change). The service used to pick a location around the player is currently the same as the previous branch. Alternatively, you can make a different service for picking up the patrol point, so the patrol radius is even narrower.

Other ideas you can implement: For the patrol state when the stimulus was sight, you could make the player do something to avoid detection (like a QT event), or make the stalker stand near an exit in case the player wants to get away. Also, make the stalker decide if it should follow or ignore sounds if its already looking for the player (meaning, the stalker is in patrolling state). This is where my AI series end, but I will share more techniques and ideas to work with AI as I test and redesign my enemy. 

Get Unreal Engine:

Sections: Tips + Tutorials

This website uses cookies to ensure you get the best experience possible More Info
Got it!