Tutorial 3 - NavMesh and AI Pathing
Tutorial 3
For this tutorial I practiced using Unity's NavMesh system to make NPCs that chase the player. The first thing I did was make a simple building that an NPC could navigate. It's a fairly simple structure with some walls as obstacles. I later added two ramps at the side for the NavMesh to work with.
Generating a NavMesh isn't very hard to do but actually getting to be consistent was quite difficult. There are many settings to take into account and you can even allow for the mesh to calculate if an NPC can walk of an edge or jump across a gap. I played with the settings until I got something that was fairly good. You can see in the image below what the mesh looks like. The arrows indicate jumps or falls that an NPC can make and anything that is highlighted blue can be walked on.
There is some awkwardness is how everything was generated and you can see some weird spots where the NPC can jump across walls or not be able to fall down a small gap. I could get this to work but I'm assuming that because these building models were thrown together fairly quickly that they aren't the most accurate. Better quality models would probably make for a better nav mesh.
I also made some obstacles including a pillar and a moving box to test the navigation of the enemies.
Next I made an NPC that chases the player using the nav mesh. Nav meshes have things called agents which a re just things that use the mesh to navigate. I made the NPC one of these agents, gave it the player's model and told it to walk at the player.
First I used the mouse to spawn enemies that chased the player.
Chasing the player
Next U placed one in the building to see how it does.
Navigating to the player
It does a pretty good job at chasing the player. It can get stuck sometimes but for the most part it was able to move to the player's location without much trouble. Next I placed a lot on enemies in to chase.
They all follow without much issue.
Overall the NavMesh tools seem pretty good if a little janky at times. It can be hard to get the settings right but I reckon that if better models are used and aligned better it will produce better results.
KIT207 Portfolio
More posts
- Tutorial 5 - Cinemachine and Post-ProcessingAug 17, 2022
- Module 5 - Lighting and ShaderGraphsAug 16, 2022
- Game ConceptsAug 09, 2022
- Module 4 - Simple Game MechanicsAug 07, 2022
- Module 3 - Terrain and ProBuilderAug 02, 2022
- Tutorial 2 - Player MovementJul 31, 2022
- Module 2 - Modelling and AnimationJul 26, 2022
- Tutorial 1 - Simple SceneJul 20, 2022
- Module 1 - ModellingJul 19, 2022
Leave a comment
Log in with itch.io to leave a comment.