FollowerEntity not catching up

  • A * version: [5.3.0]
  • Unity version: [2022.3.44f1]

Hello,

I am trying to get Player to catch up with NPC.
Player has the FollowerEntity with Speed 5.
NPC has the FollowerEntity with Speed 3.
If NPC is running to the right and Player is following, then he catches up, but Player never reaches the stoppdingDistance. If I change the stopping distance, the player will always be like 0.44f further away than just the stoppingDistance. The Player also slows down to match the speed of the NPC.

How can I solve this?
Here is a GIF: ezgif.com video to gif converter - Gifyu

Used Code:

void Update()
{
    if(isMoving)
    {
        Debug.Log(ai.remainingDistance + "/" + ai.stopDistance);
        if(ai.reachedDestination && !ai.pathPending)
        {
            isMoving = false;
            targetNPC = null;

            foreach (Action action in onDestinationReached)
            {
                action?.Invoke();
            }

            onDestinationReached.Clear();
        }
        else
        {
            if(targetNPC != null)
            {
                ai.SetDestination(targetNPC.transform.position);
            }
        }
    }
}

Hi

The FollowerEntity will slow down to a standstill at its stopping distance.
You can disable this by setting Follower Entity → slowdownTime to zero.

Alternatively, you can use some custom code to stop the agent (make sure to set the agent’s stop distance to something lower than what your script uses, in this case):

void Update () {
   var remaining = ai.remainingDistance;
   // Start/stop with hysteresis
   if (remaining < 2) ai.isStopped = true;
   if (remaining > 3) ai.isStopped = false;
}
1 Like

Wow thank you for the quick response!! :hugs:

Then I will go your way, thanks!

Second question:
How to stop the FollowerEntity?

I read in the docs to use SetPath(null) but now you mention isStopped. Whats the difference?

isStopped will make the agent stop smoothly, and keep its current path.
SetPath(null) will clear the agent’s path, and is generally not recommended unless you are teleporting the agent, or some other non-standard thing.

1 Like