Destination is setted up but AI will not move

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.

imagen

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)); }

it is solved activating RichAI CanSearch boolean.

How could this happen? Maybe it failed searching the first path?

Hi

The canSearch boolean is not something that is set by the RichAI script. So either you must have disabled it in the Unity inspector or one of your scripts must have disabled that. If it is disabled then the script will not recalculate its path automatically.

1 Like