Week 4 Tutorial - AI Navigation


This week the goal was to create Artificially Intelligent (AI) characters that could make their way across various terrains and obstacles.  In Unity, you can use a Navigation Mesh (NavMesh) to provide information to AI characters about where they can and can't walk.

 

The picture above illustrates how an AI controlled character would perceive the terrain.  The blue areas are traversable by AI, while white areas are marked as an obstacle so the AI knows not to cross into that area.  This prevents them from trying to chase the player through a fence, for example, where they would get stuck.  The arrows and circles represent places where the AI could safely jump down from one place to another without leaving the traversable area of terrain.

To create an enemy to chase the player, I added some red particles and a red trail to a copy of the player character to clearly identify them.  The player can create enemies at any place within the scene by clicking on a point with the mouse.  Upon clicking, the game calculates where the mouse is and sends out a laser-like detection beam called a raycast to that specific point on the terrain.  Once it has the coordinates of the clicked space, an enemy can be created there.


Once they are born into the world, the enemies access the player's position by searching for the Player's associated "tag", then utilise Unity's Nav Mesh Agent functions to follow a target.  In this case, they pursue the player, intelligently navigating their way around obstacles like fences using the data from the Navigation Mesh.

Leave a comment

Log in with itch.io to leave a comment.