Search Unity

Question Surround a target with nav mesh agent

Discussion in 'Navigation' started by Pytchoun, Mar 5, 2023.

  1. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    How to surround a target with nav mesh agent? The agents do not turn to position themselves and pile up behind each other instead of going around to face the target. They are therefore blocking behind and trying to push those in front.

    upload_2023-3-5_15-45-14.png
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Unfortunately, the avoidance system of Unity pathfinding is not good enough for this. You have a few different options now.

    (1) When your game has only 20-30 agents you could try giving each one a NavigationObstacle. When an agent reaches the target switch NavMeshAgent off and NavigationObstacle on. In this case, the surrounding will work like a charm.
    There are a few downsides to this. Each switch resets the pathing of all your agents, which can lead to agents not walking at all if used too often. That is why the number of agents needs to be low.

    (2) Calculate attack points around targets and let enemies claim and release those positions. Doesn't work well on moving targets but is good for immobile ones. There are still problems with this solution, as agents can get stuck when trying to circulate the target as others enemies are already in position. You could disable the ones already in place so they get ignored by the ones still looking for a spot, though this might look odd as they will walk through each other.

    (3) Write your own avoidance code to make it work. There are a lot of resources out there. Hardest solution but also probably the only one which really works if you want it to look like in Starcraft II and other RTS games.
     
  3. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    How to configure this component?
    I don't understand this part.
     
  4. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    I still waiting for your answer.