top of page

AI NPC in Hide-and-seek Games

This project aims at developing an AI behaviour that can be implemented in hide-and-seek games. AI NPCs should be able to run away from players and find hiding spots automatically. Players's goal is to find all 3 NPCs in the map.

Picture2.png

01

Visibility Test

Using the Raycast function to check whether NPC is within the player's line of sight. Different layers were set up to distinguish obstacles and the player.

Picture1.png

02

Find Hiding Spots

To hide from the player, the NPC needs to hide behind something such as walls and doors.

- Physics.OverlapSphereNonAlloc function is utilised to find and filer all colliders touching or inside the sphere within a certain range

- NavMesh.SamplePosition is called to project the given point onto nearby navMesh instances along the vertical axis. As a result, the hit points’ position will be the  world position on the floor

- Computing the dot product of the normal and the player direction to get a float which can represent the relative position of the player

- Cos90 equals 0. If the dot product is larger than 0, that means the player is in your front. So if we have a negative dot product, that means the position there is a potential hiding spot

Picture4.png
Picture3.png

03

Regrets and Possible Improvements

This game AI is using a state machine to control the behaviours. Behaviour tree could be implemented instead, since behaviour tree has a better performance. More AI behaviours could be added such as predicting player paths and evaluating path safety. Currently, NPCs may choose the path that would possibly expose their locations.

bottom of page