Tutorial 3 - NavMesh


Tutorial work

This tutorial we looked at NavMesh, Unity's inbuilt system for creating navigation meshes of the terrain and static objects in a scene. This allows characters controlled by AI to understand where they can and cannot walk in a scene - taking into account their character size and traversal abilities.

Due to my lighthouse scene not having enough interesting geometry, I opted to use the sample scene provided. I got the nav mesh created with an increased slope setting of 45 degrees to allow both ramps to be considered traversable.

I then moved onto generating the jump points, using the values of 10 for both jump distance and drop height allows for lots of jump points around the map.

Next up I brought across my humanoid character from the last tutorial. I had to remove all the animation and character controller code to allow it to work as nav mesh agent where it would control itself.

I implemented the sample ray casting code to take the 2d position of the user's mouse (on the screen) and find the closest point in the 3d world under the mouse. The character was then given this 3d location point as a target to try and reach - the AI controller would then work to get to the target using the nav mesh to find the shortest path.



Portfolio work

I added Navmesh to my Tasmania tourist scene, as well as some more geometry to make it a bit more interesting. I then added a basic moving object using a cube that moved between two points (two empty game objects).

I then trialed various Nav Mesh settings to see how it performed running with the moving object. It seemed okay even when calculating whilst moving, mainly because it only intersecting a rather simple mesh (in the carpark), if it moves further onto the terrain it really slows down.

Next up it was time to adapt last weeks ray tracing code to place barrel objects. This code now waits for a mouse click, then finds the first solid objects. When found it then places one of the red barrel objects on top. This barrel will soon be setup to chase the player.


I put in some very basic following logic for the barrels, they simply seek the current position of the player. Not currently taking into account any future position based on the player's velocity or rotation. The barrels also can run though each other and do not correctly follow the Nav Mesh yet.


Leave a comment

Log in with itch.io to leave a comment.