Search Unity

How to make a crowd of agents around an area.

Discussion in 'Navigation' started by Aequitatis, Nov 2, 2017.

  1. Aequitatis

    Aequitatis

    Joined:
    Jan 24, 2014
    Posts:
    12
    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!
     
  2. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    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
     
    JBR-games likes this.
  3. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    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 .
     
  4. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    HI,

    Instead of adding multiple empty objects, try simply adding a random radius to your target each time you want to go there.

    -Miggi124
     
  5. Miggi124

    Miggi124

    Joined:
    Jul 31, 2017
    Posts:
    69
    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
     

    Attached Files: