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;
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:
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