Pathfinding weird behavior of player

I would like to setup pathfinding navigation in a scene, I am following the example provided in this library

I am observing a strange behavior, when following a path sometimes the player remains stuck in a checkpoint, oscillating between two positions.

Because of this, most of the time the player is unable to follow a path along a border.

I’ve prepared a plunk to show this:

Could be a problem with my navigation mesh (although it seems very basic) or with the code?

Thanks for any help!

In this section of your navigate function:

      if (velocity.lengthSq() > 0.05 * 0.05) {
      } else {

The 0.05 value is basically an error margin for how close your player needs to be to the target before it can stop moving. If your character is moving more than that distance every frame, it may overshoot, go back, and repeat this infinitely. So you just need to choose a value that’s a little larger than the distance the player moves each frame. In this case, 0.5 seems to solve the problem.

1 Like

Thank you, perfectly clear now!