Unity: NavMesh, Crowd Behaviour and Wander AIs

If you’re interested in creating projects or games with Unity that utilize or simulate crowd behavior (think FPS with zombies and wandering NPCs), I found this video from Holistic3D to be extremely helpful as a starting point. This tutorial is very simple and uses a combination of Navmesh and way points to give your AIs (agents) the semblance of movement with a crowded environment.

This is very basic setup but it can be easily built upon. As an example,  if you don’t want to use waypoints, you can employ something like a simple wander script if you prefer to make your AIs appear just a little more “human” in a sense. We’ve talked about how to create AI wander scripts which is not all that complicated, but for now let’s look at this really cool demo on simulating crowd behaviour using a Dynamic Navmesh. The end result in the demo below actually illustrates less of a crowd and more of a kind of ‘mob’ behaviour, but that is for you to decide:

I won’t write up a whole step-by-step walk through on how to code this for you since following the tutorial in the video will be much more valuable from a visual standpoint. Setting up your Unity project for Crowd Behaviour is however very simple when you follow these steps.

How to create a basic crowd behaviour AI in Unity

This is just a summary. Watch the above video for a clearer, more visual tutorial.

Once you’ve set up a new project in Unity, start by creating a plane, add some cubes for walls, create some cylinders (agents), assign waypoints for each and most importantly, add navigation “boundaries” to your map via the aforementioned Navmesh. Finally, you will just need a small bit of code to attach to your agents will help them to navigate to their respective home locations. Once the basics are in place for your individual agents, you can simple hit CTRL-D to duplicate them to as many agents as Unity will allow (or as much as your PC can take).

And that’s pretty much it. If you followed along carefully, you now have an Instant Crowd. Happy creating!

3 thoughts on “Unity: NavMesh, Crowd Behaviour and Wander AIs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.