Working with Unity’s Nav Mesh System for Smart AI

Simon Leen
2 min readAug 3, 2021

--

Objective: Stop the Player walking through and clipping objects.

Following on from the last post, we can see in the above image that our Player is moving on click but is going through and clipping the other GameObjects in the scene. We need to fix this so that the Player goes around the objects.

It’s actually not too difficult to fix. It just means rebaking the scene but with one difference. We need to change the other GameObjects that we don’t want the Player to travel through to static so that the mesh knows these objects are obstacles that need to be avoided.

You will notice the outline or highlighting on all the objects in the scene. These are all the selected GameObjects that will now be set to static and rebaked with the NavMesh. Once these have all been set to static, go back to the Navigation panel and clear the old baked data before baking another one.

The above image is the old NavMesh. As you can see the blue highlighting doesn’t stop near the objects. In fact it passes underneath them.

This is our newly baked NavMesh. As you will notice the blue highlighted mesh stops and leave an area around each of the objects. This is as far as our Player can travel so no more moving through objects.

--

--

No responses yet