# How to make a crowd of agents around an area.

Hello all, thanks for your attention.

I’ve tried doing this for quite a while, with some success, but ultimately it has all fallen apart under later changes.

The Situation
I have a table, with which I want a number of NavMeshAgent actors to approach and crowd around. Imagine people standing in front of a stage watching a performer. Once they have arrived they must stay still.

Approach so far
At the moment my most successful approach has been to add triggers to the table showing where I allow the actors to stand and crowd. When an actor is spawned, he finds the closest point in those triggers and navigates to it. Every second a coroutine runs which updates the closest point. It checks if that point is within a collider (specially attached to every actor for this purpose only) - if it is the position is taken up by another actor. I then find a point a distance to the right or left (randomised), calculate the closes point from there, and navigate there. I recursively check if these points are occupied up to 4 times, if it fails then I just halt.

This used to work, but now I get some spectacular orbiting effect, where one actor will spin around another one in its place super fast.

Is there a better approach or tool or facility I’m missing that will help me with this?

Thanks very much for any ideas!

Hi,

Quick answer - try writing a simple script assigning the target a random speed between, say, 3 and 5. Now, all you have to do is simply set a destination (and space them apart from each other manually before the game starts), and you have a simple crowd effect. I will probably come back with a better answer, but for now, feel free to try this.

-Miggi124

1 Like

Add a bunch of “empty game-objects” around your “Area of Interest” put them in an array or list. then as @Miggi124 suggested go through each agent and set random speed, and set destination to each “empty game-objects” transform.postion .

HI,

-Miggi124

Hi,

This is for @Aequitatis , or anyone who wants a solution. I’ve just made a simple project that you can look at that shows my solution in action. Feel free to use it in anything, but please don’t claim it as your own. I hope this can help you, and if you have any questions, feel free to ask me.

-Miggi124