Hey so i’m using NavMeshAgents and i’m moving them around by clicking on a place in the world, and all they do is move there. That simple. How can I avoid the agents clumping together?:
As you can see from the video attached above, just regularly moving one agent to a specific spot that I click is working just fine. But when assigning multiple agents to a spot, they all appear to fight eachother for the spot and never reach their destination. This also means that their navmesh velocity will always be over a vector zero. Which is really important because it can be useful for animation, and other functionality.
What I’ve Tried:
How can I make them not clump up like this? I’ve already tried:
- not detecting collision between eachother.
- I’ve tried putting navmesh obstacles on each of the troop (agents)
- ive tried creating an overlap/checksphere on the position of my mouse click and checking how many agents have entered the list.
- I’ve tried checking if their current velocity is under a current number.
This is my unit movement script:
public class UnitMovement : MonoBehaviour
{
Camera cam;
NavMeshAgent nav;
public LayerMask ground;
void Start()
{
cam = Camera.main;
nav = GetComponent<NavMeshAgent>();
}
void Update()
{
if (Input.GetMouseButtonDown(1))
{
RaycastHit hit;
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity, ground))
{
nav.SetDestination(hit.point);
}
}
}
}
I’m not sure what to do. Please any help!