Portfolio 05 - Navmesh Agents


Final Result


This week I set up a navmesh agent and navmesh using the terrain created last week, also modifying my character made previously to use a top-down camera.

Additionally created an animated navmesh obstacle that the navmesh agents can interact with.

As a starting point I began by setting my terrain mesh and bridge models to Walkable inside the Navigation options, also changed the bridge models to convex collision options so that the detail is more simplified in the collider.

After baking initially produced these results.

As you can see the navmesh is not covering my whole terrain, after investigation, I learnt that the foliage is considered in my navmesh bake so an online solution I found said to just delete the foliage and add them again after baking the navmesh.

After tweaking the setting on the navmesh bake, specifically reducing the radius on the nav agent allowed me to include the surface right to the edge of an object. Also setting the plane for the water to Not Walkable automatically excluded that section from the navmesh, finally setting Generate OffMeshLinks allowed me to automatically set the side of the bridge, an edge the agent can run off.

Now on to the navmesh agent, setting up the basic agent and a controller script was very straightforward after following the tutorial, The code below simple tracks the player's position + their velocity which generates a rough approximation of the player's position, and then sets the nav destination to that position. Also setting the animator float value to the nav agent speed, easily allowed me to use the character controller made earlier.

After this was working I decided to add a few enemies and also a falling block animation that acts as a Navmesh obstacle, and can destroy the enemies, this block was hand-animated in unity and a basic state machine setup to repeat the animation after a set time.

As you can see it's a basic script to destroy the enemy, and trigger the animation state change on a specified interval, in this case, seconds.


Finally, I added the ability to click to spawn enemies using the modified character controller raycaster script, as you can see it simply instantiates an enemy instead of set the destination as it did before.


Thanks for reading through.

Get UTAS KIT207 Portfolio

Leave a comment

Log in with itch.io to leave a comment.