top of page

GUARD AI FOR STEALTH GAMES

This AI template represents my dissertation project. The Guard AI features complex logic, multiple states, a dynamically adaptive patrol route and communication between allied AI guards

Noticeable features implemented

A dynamic patrol route that adapts based on how much time has passed since an area has been checked

Communication between AI NPCs. Alerting close NPCs when spotting enemy and advancing using specific techniques towards the player

Cover system, peeking from cover and switching positions

Hunting state where the NPCs will search for the enemy around the last seen position

Dissertation Project

 

What i did: Created an AI guard NPC template for stealth games with dynamic patrol route and a response to threat based on a technique used by the US Military Rangers. Designed and programmed the whole AI behaviour as it was a solo project.

​

User feedback: Received positive feedback on the AI complexity and how well the blueprints were commented and organised. Also received very good feedback on how I managed to create some functions that were supposed to be done in C++, by only using blueprints.

​

Team size: 1 member

​

Project length: 1 month

​

Year: 2021

Capture6_PNG_edited.jpg
Cover, Peeking and Switching cover side_.webp

Project goals

​

  • Challenge myself to learn how to implement more complex features using Unreal Engine

​

  • Create an AI template that can be used as a base for stealth games

​

  • Obtain a good grade which has a lot of impact on the whole degree

EARLY STAGES

Design goals

 

  • Implement a dynamic patrol system, but still retain control over what area the NPCs must cover

​

  • Make the AI respond to threat based on a technique used by the US Rangers

​

  • Create a more realistic AI behaviour that is still fun to play against

The core goal of this project was to create an AI NPC that acts in a more realistic way while still being fun to play against and does not impact a game's immersion like NPCs with predetermined patrol routes do.

This patrol system is achieved by using an AI concept called "staleness". The level is divided into areas using custom actors made of volumes. Each volume has a staleness value represented by a float variable. When a guard AI walks through one of these areas and "sees" it, the float value is reset to 0. The AI will always try to prioritize areas with a higher staleness value (areas that the AI hasn't checked for the longest time). Using this, the AI will dynamically adjust its patrol route and thus, there is no pattern that the player can learn. This feature supports replayability and makes each playthrough unique.

The second and most complex feature of this AI is its communication with allied guards in its "Fighting" state. In order to make this AI unique, I made it advance towards the player using a concept from the US Military Rangers called "bounding overwatch". Using this technique, forces will advance on the battlefield in groups, each group at a time. One group covers the other while it advances and vice versa. The group that advances will only use paths that are in the line of sight of the group that is "overwatching".

When the AI sees the player, it will immediately go into cover and alert nearby allies. After peeking from cover for a few times, it will try to advance towards a cover that is closer to the player. It will only advance if an allied guard has line of sight of the path and final position so it can always provide covering fire if needed. If the AI cannot advance in this way, it will try to reposition closer to the allied guard before trying to advance again.

The AI also features multiple states which control its behaviour. There are states such as fighting, hunting, investigating, alerted patrol, calm patrol etc. The AI will also never return to the calm state if it has ever seen the enemy.

​

The custom made AI controller currently features two implemented senses (sight and hearing) and also made it possible for the AI to detect friendlies without using C++ to modify classes.

A main focus for this project was to make it easily editable in order to be used by designers or level designers and eventually publish it on Epic's Assets Marketplace.

Multiple features can be added, removed or edited, such as:

​

  • Alert range for nearby guards

​

  • FOV and view range

 

  • Movement speeds for each AI state

​

  • Duration and range of investigating last seen player location

​

  • How many times the AI peeks from cover

​

​

PROCESS PROBLEMS

AI Controller_PNG.webp
Behaviour Tree_PNG.webp

Obstacles

​

1. The NPCs will chaotically roam around the level at first, eventually discovering the optimal path to cover the whole area and falling into a set patrol pattern.

 

2. The AI will perceive other NPCs as enemies and not neutrals or friendlies, the only apparent solution being creating custom classes in C++, as affiliation cannot be changed using blueprints.

Solutions

​

1. Separate the areas that need to be checked into smaller chunks and assign specific zones for each NPC to roam

​

2. Stop using the default "Detect by affiliation" system in Unreal Engine and choose a behaviour path on actor detection, based on custom given tags.

Because the NPCs were roaming wherever they needed around the whole level, they would all gather around the same area in the beginning as that was the least visible one. Eventually, after checking out the whole map, they would start to form a predictable pattern. By separating the areas into smaller parts, the AI would have more options to choose from based on a score system. On the way to check an area, it would also view other parts of the level and classify them as "checked", dropping their staleness value to 0 and not needing to check them again for some time. The small areas that needed to be checked were also assigned a name. Each NPC can be told specifically what are the only zones it can patrol around. This made it possible to have a more believable patrol system and also have control over the placement and number of NPCs in each area.

With the entire detection system implemented and fully working for 1 AI, it was time to make them communicate to each other and advance together towards the player. Unfortunately, the NPCs would detect each other as enemies if the default detection was active. If the default detection was inactive, the NPCs will not detect anything, including the player character. Trying to find a solution to set other NPCs as friendlies, I only found methods that included creating and modifying the classes using C++, as it could not be done in blueprints. I did not have the time to learn how to do this and modify my whole project at that moment due to the deadline being somewhat close. I decided to leave everything default regarding the detection by affiliation wise and create two separate behaviour paths the AI can take when detecting an "enemy". It would take the first path when detecting another NPC as an enemy and not do anything, unless needed to provide cover or communicate. The second path would be chosen when it detects the player, entering the cover state and advancing while communicating with any NPC that is close, covering each other.

OUTCOME

Check Overwatch_PNG.webp
BTTasks, Services and EQS_PNG.webp

Project

 

  • Managed to fully implement all features initially intended

​

  • Created a patrol system that can easily be used in many game genres 3D and 2D

User feedback

 

  • Received positive feedback on the complexity of the AI systems

​

  • Received some negative feedback on the polish level of the advancing system, because it had some small delays and felt a bit rough

​

  • Received a good grade that helped me receive my 2.1 degree

Even though I spent a lot of time designing and implementing the AI as it was my dissertation and a passion project too, I realised how well a blueprint template must be polished in order to be uploaded on the Epic Marketplace and be easily used by other developers. I learned that the complexity of the features really grows fast and must be carefully planned ahead.

bottom of page