Search Unity

Can you 'spread out' NavMesh Agents?

Discussion in 'Navigation' started by jxj5614, Apr 8, 2019.

  1. jxj5614

    jxj5614

    Joined:
    Nov 14, 2018
    Posts:
    4
    Hello all,

    I am working on a zombie survival FPS to learn Unity better. Navmesh has been alright so far, but I am having a problem that has been a pain to try and solve.

    Right now, I am setting the player as the destinations for all the zombies as soon as they spawn, which causes the zombies to run to the player in a "conga line" sort of formation which makes it really easy to just aim in one spot and pick them all off.

    Does anyone have any suggestions about how I can make the zombies run at the player in a more 'horde' or crowd sort of formation rather than in a straight line?

    Thank you!!!
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    The pathfinding system gets you the shortest path to the destination. Any kind of pattern/formation you need to plot out the destination points yourself. Which can get a little complicated if you want it to work well at all ranges.

    Like for near the player you could use Random.insideUnitCircle to distribute the zombies, so not all of them stack right on the player.

    At some longer range you have no choice but to plot intermediate paths. You would need to do something like calculate the path, use the corners as a guide for a set of intermediate destinations that you plot between the corners. Offsetting those intermediate destinations by some amount to ensure distance between zombies.

    This is something experts would spend a decent amount of time solving well, it's not an easy problem after accounting for all of the edge cases. Near the player is the easiest part of it to get to an 'ok' point, that's what I would suggest doing and punt on the rest as you could literally spend weeks on it.
     
    jxj5614 likes this.
  3. jxj5614

    jxj5614

    Joined:
    Nov 14, 2018
    Posts:
    4

    Thank you!!!

    This does seem very complex and I am somewhat new to C#.

    I had an idea recently that might help. Right now I created some default spawner prefabs that I use to spawn enemies, but your comment about the unit circle got me thinking of potentially scrapping the spawners (Which will always make the zombies come out in a line) and just spawn zombies at a random point a far distance out of a large unit circle around the player, so that they are always coming from different directions. Might make it seem realistic