The code for Godot navigation is wrong in the course. The way it’s currently coded is:
- The AgentNode target position is set and Move () is called.
- Move() then calculates a path to the target position by calling GetNextPathPosition(), but does nothing with the returned value. The returned value is what we want, since it’s the next point along the generated path.
- The character velocity is then set to point to the “destination”, but the destination isn’t what we want, we want to follow the path, and so we want the value returned from the GetNextPathPosition().
- MoveAndSlide() is then called, but since we are telling it to head in the direction of the last point in our path, all pathing is ignored and the character makes a beeline for the target.
Instead you need to use the returned value from GetNextPathPosition(). I recommend changing the move code to the following:
Vector3 nextPathPosition = characterNode.AgentNode.GetNextPathPosition();
characterNode.Velocity = characterNode.GlobalPosition.DirectionTo(nextPathPosition);
characterNode.MoveAndSlide();