Hi there, I have a city and 100 navmeshagent citizens to roam in city. They take a random destination from script and go there. When they are close to their destination they take another random destination. But in order to move it looks like they are waiting each other like they are in a queue. They start their movement one by one and when they are close to target they stop and wait like they are in a queue. They all have their own scripts in their prefabs which allows them to move. Any of you know the solution to this problem? I couldnt find anything on the internet. Here is my source code:
public class FreePopulation : MonoBehaviour
{
public NavMeshAgent theAgent;
public float x;
public float z;
public Vector3 target;
public Animator animator;
// Start is called before the first frame update
void Start()
{
theAgent = this.gameObject.GetComponent<NavMeshAgent>();
animator = gameObject.GetComponent<Animator>();
RandomDestination();
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance(transform.position, theAgent.destination) < 8)
{
RandomDestination();
}
if (theAgent.velocity.magnitude < 0.2f)
{
animator.SetBool("Idle", true);
}
if (theAgent.velocity.magnitude > 0.2f)
{
animator.SetBool("Idle", false);
}
}
public void RandomDestination()
{
x = Random.Range(-100, 101);
z = Random.Range(-100, 101);
target = new Vector3(x, transform.position.y, z);
theAgent.SetDestination(target);
theAgent.isStopped = false;
}
}