Using box collider to determine if AI should stop help

Hey guys. Situation - I have civilian AI roam around randomly from waypoint to waypoint - they use raycast to avoid one another - which works pretty decent, but sometimes 2 AI reach the node around the same time, and also attempt to head to the next waypoint at the same time, they stack into each other… I attempted to put a box collider on them as a child so they would stop if following to close until the exit happens from the other one they are following, and to prevent them from stacking into one another, but this just generated a few more problems.

AI will now run into each other, the colliders will both register and the never-ending face off happens. I lack the logic on my part to figure out a system where the AI will stop and allow another to move away, and then keep on his path… because they both are using the same collider on the same layer.

Here is a simple snip of the script I’m using to talk to my AI script (just using the speed var in there to force the stop)

using UnityEngine;
using System.Collections;

public class AIStop : MonoBehaviour {
	private bool wait;
	public AI ai;

	void Start () {
		wait = false;
	}

	void Update () {
		if (wait)
		{
			ai.speed = 0f;	
		}
		else{
			ai.speed = 5f;
		}
	
	}
	
	void OnTriggerEnter(Collider AIPED)
	{
		wait = true;
	}
	void OnTriggerExit(Collider AIPED)
	{
		wait = false;
	}
}

Without this weak attempt a collider if I keep the population low they appear to work fine because the chance of them getting to the same waypoint at the same time is low - but thats a workaround, not a solution… just interested to hear other peoples approaches and ideas.

Hey ,

Since you know who you are colliding with for example AIPED then you can do something of the sort

if (AIPED.getComponent<AIStop>().wait == true){
wait =false;
}else{
wait = true;
}