Search Unity

Multiple enemies to attack one target but not stack up on one point

Discussion in 'Scripting' started by Lyquifire, Mar 19, 2018.

  1. Lyquifire

    Lyquifire

    Joined:
    Jan 1, 2018
    Posts:
    5
    So i have this game where enemies are generated and attack this giant crystal. Of course they all have nav mesh agents, and in their scripts i set the agents destination to be that crystals transform.position. But incase multiple enemies are attacking the crystal, they all attack the exact same point and end up stacking up in a line. How can i make these agents target the entire crystal and not just that point, so they end up surrounding the crystal rather than standing in a line to attack that one point.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Two approaches to try:
    • You can try putting a Nav Mesh Obstacle on the agents. (https://docs.unity3d.com/Manual/class-NavMeshObstacle.html) This makes agents avoid spots that something else (including other agents) are currently occupying.
    • If your agents have colliders on them, that should prevent them from stacking up. They'll kind of push each other around a bit.