How to stop on path before reaching the end

Hi everyone,

Hoping someone can help, cause i’m stumped. I using the basic Grid path, and what i’m wanting to do is have the object stop when it reaches a certain distance from the end of the path (another object). What is the best way to do this?

Thanks in advance.

Hi

If you use one of the built-in movement scripts (e.g AIPath), then you can set the endReachedDistance field and also set ‘When Close To Destination’ to ‘Stop’.

This will stop the AI once it gets within a certain distance from the end of the path (which may or may not be at the destination, if the ai cannot reach that point).

An alternative way is to do

void Update () {
     ai.isStopped = Vector3.Distance(ai.position, ai.destination) < someDistance;
}

I didn’t even notice that field, thanks. That’s exactly what I needed.

1 Like