I am calling this function with a “InvokeRepeat”. If the AI is moving (it has not reached the destination) it will do nothing, but if it has reached the position it will move to a new one.
As you can see, the AI has not reached the position, the distance is higher than 1 and IT IS NOT MOVING.
If I move manually the AI in the inspector it will move to the last position, seems like it is stucked at the last recogniced position.
It works pefectly most of the time, but when I have some AI’s moving around the scenario, sometimes some of them have this strange behaviour. Do you know why this happens?
I have not setted up any dynamic collision or local avoidance.
ai.isStopped = false;
ai.isStopped = Vector3.Distance(ai.position, ai.destination) < 1;
if ( ai.isStopped ){
Vector3 area = GetRandomZoneAreaDestination();
ai.isStopped = false;
ai.destination = area;
ai.SearchPath();
}
if (debug_code){ Debug.Log(this.GetType() + " | " + gameObject.name + " | ai.isStopped = " + ai.isStopped); }
if (debug_code){ Debug.Log(this.GetType() + " | " + gameObject.name + " | ai.position = " + ai.position); }
if (debug_code){ Debug.Log(this.GetType() + " | " + gameObject.name + " | ai.destination = " + ai.destination); }
if (debug_code){ Debug.Log(this.GetType() + " | " + gameObject.name + " | Vector3.Distance(ai.position, ai.destination) = " + Vector3.Distance(ai.position, ai.destination)); }