Best way to "Instant stop" with AIPath?

Version of A* Pathfinding Project: v4.2.15

Hello there.

I don’t know what is a best way to force AIPath to instant stop, when it is near destination.

On video bellow problem is illustrated.

(After I press “Party - Follow” button, I set my “Player” transform into “AIDestinationSetter.target”)
AIDestinationSetter.target = player;

https://youtu.be/7PBC-EBGwbU

Each square from video is 1 unit diameter.
While I did set “EndReachedDistance” and “SlowdownDistance” as “3 units”, you can clearly see that “EndReachedDistance” doesn’t really work (at least as I expect it to work), and agent still “slide” to my player much closer than “3 units”.

I wasn’t sure how to deal with it, but parsing forum I found that we can set “AIPath.canMove” to “false” in order to achieve “Instant stop”.
I’ve tried it using this code:

void Update()
{
	var distance = Vector3.Distance(agent.position, player.position);
	if (distance <= agentAIPath.endReachedDistance)
	{
		agentAIPath.canMove = false;
	}
	else
	{
		agentAIPath.canMove = true;
	}
}

Unfortunately, it raises another problem.
If agent STOP move (because he is too close to player), and my player then start to run in opposite direction, then when agent START move again, it looks like he still saved some velocity from previous movement, thus he “slide” in incorrect direction for some time, before turning around and proceed to follow player.

Here’s a video which demonstrates this issue:

https://youtu.be/ladTwgyxN78

Any ideas how can I achieve “Instant stop” without this “sliding” behaviour in incorrect direction, after re-enabling “canMove”?
I thought maybe there is some way to “reset velocity”, but didn’t found anything.

p.s. agent inspector:
https://imgur.com/a/ncPIkUI

Hi

You can use

ai.isStopped = true;
ai.desiredVelocityWithoutLocalAvoidance = Vector3.zero;

However, the desiredVelocityWithoutLocalAvoidance property is only available in the beta version. You can find it here: A* Pathfinding Project

You can object “AIDestinationSetter.target” set to it self, so it will be immediately to stop in place,

Blockquote
//When you need to stop
AIDestinationSetter.target = this.transform;

//When you need to move
AIDestinationSetter.target = newtarget;

and there are no side effects, when the need to move, change it “AIDestinationSetter.Target”. This is the way I use it in my own projects, and I hope it works for you. :grin:

I’ve solved this issue in the past by adding new value to enum “CloseToDestinationMode” like “InstantStop” and minor tweaking logic inside of “AIPath” method called “MovementUpdateInternal”.

Now after I’ve updated to version 5 using “Install using UPM” installation option, I’ve found that source code is no longer can be edited by myself.
So I wonder @aron_granberg if you can add this logic to AIPath and update package (since I have no git access I can not do this using “pull request” mechanism).
If not, I guess my only options is to create a new class derived from AIPath where I will be able to override method logic, or re-install package using normal copy-paste installation option.

Hi

I haven’t tested this, but I think you should be able to do something like this, in a separate script:

void Update () {
    if (ai.reachedDestination) {
        ai.isStopped = true;
        ai.desiredVelocityWithoutLocalAvoidance = Vector3.zero;
    } else {
        ai.isStopped = false;
    }
}