Trying to stop agents fighting over same destination

Hi, I’ve been working on a rts using unity navigation and I was wondering if there was a way to stop 2 or more nav mesh agents fighting over the same destination.

for instance im using this click to move script to move 2 or more agents.

if(Input.GetMouseButtonDown (1) && selected == true)
        {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;
           
            if(Physics.Raycast(ray, out hit, 100))
            {
                agent.SetDestination (hit.point);
                anim.SetBool("walk",true);
            }
        }

and im using this when the agents reach there destination

if(agent.remainingDistance <= float.Epsilon)
        {
            anim.SetBool("walk",false);
        }

is there a way to stop the agents from fighting over that one spot and just take the nearest available position.

If anyone could help it would be greatly appreciated.

As long as you use the same destination for each nav mesh, they are going to try to reach the same point.

  1. You can change the stopping distance so the agent stops when close to the destination point.

  2. You can give each unit its own unique destination point.

yeah I’ve messed around with the stopping distance it didn’t give the effect I wanted. I was wondering, in order to give each unit its own unique destination point could you use “Random.insideUnitSphere” along with the mouse click.
something like this…

Vector3 uniquePoint = Random.insideUnitSphere * mouseHit;
         NavMeshHit hit;
         NavMesh.SamplePosition( uniquePoint, out hit, mouseHit, 1);
         Vector3 finalPosition = hit.position;  
        agent.SetDestination (finalPosition);

not to sure if that would work haven’t tested it yet. I’m pretty sure I have got a few things wrong there though.