Navigation agent never reaching next path position

Godot Version

Godot 4.5

Question

Hello there!

I’m having trouble with some navigation agent unable to go through the path. I set up a navigation region, baked the mesh and the navigation path generated for the agent looks right.

However it seems the navigation agent get stuck whenever reaching the first next_path_position.

I logged the global_position of my agent and the next_path_position when and it seems to loop when trying to reach the path position:

(-0.607327, 0.15, 4.001292)(-0.5, 0.15, 4.0)
(-0.474003, 0.15, 3.999687)(-0.5, 0.15, 4.0)
(-0.607327, 0.15, 4.001292)(-0.5, 0.15, 4.0)
(-0.474003, 0.15, 3.999687)(-0.5, 0.15, 4.0)

It seems it’s never reaching the exact next_path_position so then it never gets to the next one. Although i have the Path desired distance set up to 5.0m so i would expect that as soon as it approach the next_path_position by 5m it will update to the next one.

My agent is a character3D that has no collision set up so it shouldn’t be a collision issue.

Could someone help me understand what’s happening ?

Here is the code of my character 3d (taken directly from the doc):

extends CharacterBody3D

var movement_speed: float = 8.0
var movement_target_position: Vector3 = Vector3(-100,0,121)

@onready var navigation_agent: NavigationAgent3D = $"../NavigationAgent3D"

func _ready() -> void:
	navigation_agent.velocity_computed.connect(Callable(_on_velocity_computed))
	navigation_agent.set_target_position(movement_target_position)

func _physics_process(_delta):
	# Do not query when the map has never synchronized and is empty.
	if NavigationServer3D.map_get_iteration_id(navigation_agent.get_navigation_map()) == 0:
		return
	if navigation_agent.is_navigation_finished():
		return
	var next_path_position: Vector3 = navigation_agent.get_next_path_position()
	var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_speed
	print(global_position,next_path_position)
	if navigation_agent.avoidance_enabled:
		navigation_agent.set_velocity(new_velocity)
	else:
		_on_velocity_computed(new_velocity)

func _on_velocity_computed(safe_velocity: Vector3):
	velocity = safe_velocity
	move_and_slide()

It does look like the target distance is set to something too small so it keeps jumping over the target position.

Maybe try printing path_desired_distance too just to make sure it uses the value you set. Also make sure path_max_distance and target_desired_distanceisn’t too small either.

I printed the path_desired_distance path_max_distance target_desired_distanceand got the following 5.0, 5.0, 1.0 which corresponds to the value i set.
The agent is moving properly until it “reaches“ the next_path_position, the issue being that it never gets updated

Newbie here myself… But I ran into your comment looking for a solution to the exact same problem. I also had the NavigationAgent3D as a sibling of the CharacterBody3D. I moved it to be a child of the CharacterBody3D and it works just fine. I’m curious if the issue here is the CharacterBody3D is moving, but not taking the NavigationAgent3D with it. This means the CharacterBody3D does reach the path point, but the actual NavigationAgent3D does not… still sitting around at it’s original location.