Thanks to new Unity 4.0 version, we can use a feature that was only available in the Unity Pro version: NavMesh
After some research, we discovered how to let Unity3D to manage, in a very good way, the pathfinding of our AggroEnemies: they can recognise the entire map design and we don’t need to care about the programming. We don’t even know what algorithm is being used by Unity3D, but it works!
To make it work, you need to add a new component called ‘NavhMesh Agent‘ to a GameObject. This is the ‘controller’ that automagically moves the GameObject through the NavMesh baked.
But before, you should define every game prefab that could collide with the GameObject (in practice, the entire map) with the NavMesh Agent as ‘static’.
Later, you can individually disable it in the Navigation Menu: for example, a zone that you don’t want an Enemy to go through.
However, we have faced some problems related to NavMesh Bake general configuration:
- Some slopes were not totally covered with NavMesh. Although our slopes have a 45º angle, we had to adjust the ‘Max Slope‘ value to 55 to get them completely cover by the NavMesh.
- When adding some new prop (big tree), the new NavMesh Bake covers totally or partially the prop. We did not test it, but that means that the Aggro Enemies could walk over the top of the tree.
- You can also observe that sometimes, the NavMesh triangulation gets corrupted or overlaps itself. This is, by far, the most difficult problem to solve without changing the map design.
Luckily, we have resolved them by trial and error, adjusting NavMesh values.