Weird behaviour of Follower Entity when moving to destination above head

  • A* version: [5.3.8] (Pro)
  • Unity version: [2022.3.47f1]

There is a problem with Follower Entity when it tries to reach destination that is above its head.

I have staircases in my game, and monster is supposed to walk on them. When monster is chasing player, stoppingDistance is set to 2f, so monster will stop normally near the player (but not very close) and kill him.
But when the player is on the 2nd floor (for example), and monster is running under him on the 1st floor, it suddenly stops moving, showing speed = 0. reachedDestination and reachedEndOfPath are always false (because there is piece of code that checks if destination is above head or lower than 0.5 of height of monster). BUT the remainingDistance is a bit lower than the current stoppingDistance (that was set to 2f), and I assume that this forces Follower Entity to stop.
Gizmos shows correct path to player.

Screenshot of this situation. Player is on the 2nd floor (blue skeleton), monster is under him, path is drawn in orange

And the calculation of remainingDistance is very weird as for me.
First of all, the straight distance between monster and player is way more than 2f.
Second, the full path length must be even longer.

I searched for a code that calculates the remaining distance, and found, that in JobRepairPathHelpers.UpdateReachedEndInfo() it calculates this value using some corners values. When I tried to debug this, it shows me that there is only 2 elements in corners collection - first is the monster position, second is current corner it is avoiding (shown in red on the picture above). Then (in PathTracer.RemainingDistanceLowerBound()) it sums lengths between all corners, and adds the distance from last corner to the end of path (player) ignoring y component of distance (in NativeMovementPlane.ToPlane()).

As far as I understand, that’s the way it gets remainingDistance. And it’s really smaller than stoppingDistance = 2f.

So my questions here:

  1. Is it a bug? If it is, how can I fix it?
  2. Is it a problem of bad parameters of Graph / FollowerEntity?
  3. There is a comment from developer above this code:
    // TODO: Edit GetNextCorners so that it gets corners until at least stopDistance units from the agent
    Maybe its a fix, and developer has already implemented that. Then what version I am supposed to download, because I can’t find anything about this in release notes of newest versions

I tried to describe as much as I knew :slight_smile: Any help or information will be really appreciated. Thank you!

I can’t answer this directly, but instead of relying on stopping distance, it’s fairly simple/fast to calculate the distance to the other agent manually (along with any restrictions you want, like making sure they’re within a certain Z distance of each other), and then stop the agent manually when you are happy with the positioning.

1 Like

Based on that comment you found in the code I’d just say this is something Aron is aware of but hasn’t gotten around to. I guess it’s technically a bug, yeah.

Honestly I’d go with dvneal’s solution as that was my first thought. The way it works now is sub-optimal and assumes a simpler more straightforward map, but I think it’s a actually a better idea to make your own handler for stopping “within a distance” that’s better fit to your game. Like maybe checking the distance on only X and Z, raycasting for doors, etc.

Hi, @dvneal and @tealtxgr
Thank you for your replies! Yea, I already implemented custom target-reached checking for my monster, so now it works ok as for me.
For anybody who can be interested in solution, I made next steps:

  1. Decreased stoppingDistance to a small value (like 0.1 was enough for me, it can be less but remember that it must be more than 0), so this bug never occurs
  2. Implemented custom logic that checks distance (that you wish to be stoppingDistance - 2f in my case) to target on XZ plane but takes into consideration the Y component like it is implemented in A Star Pathfinding - by checking if its not above agent height or below half of agent height down. Also it has raycast logic for checking if there is no obstacle between agent and destination - so we can assume that agent reached it.
1 Like