Object floats in air using NavigationAgent3D

Godot Version



My CharacterBody3D object is following the navigation path as expected using the NavigationAgent3D.
It reaches the destination but at some point starts to float and glide along the navigation path instead of staying on the ground (see clip)

Is there a way to make it just follow the path but stay on the ground?

func _physics_process(delta):
	# https://www.youtube.com/watch?v=-juhGgA076E
	var current_location = global_transform.origin
	var next_location = nav_agent.get_next_path_position()
	# https://kidscancode.org/godot_recipes/4.x/3d/rotate_interpolate/index.html
	var newPos = Vector3()
	newPos.x = nav_agent.target_position.x
	newPos.y = global_transform.origin.y #this is required to make sure the transporter always looks straight ahead
	newPos.z = nav_agent.target_position.z
	var new_transform = self.transform.looking_at(newPos, Vector3.UP)
	self.transform = self.transform.interpolate_with(new_transform, 1.0 * delta)
	var new_velocity = (next_location - current_location).normalized() * SPEED
	nav_agent.velocity = new_velocity
func _on_navigation_agent_3d_velocity_computed(safe_velocity):
	# https://www.youtube.com/watch?v=-juhGgA076E
	velocity = velocity.move_toward(safe_velocity, 0.1)

I kinda fixed it by adding

	safe_velocity.y = 0

to _on_navigation_agent_3d_velocity_computed() but is that the correct solution?


The NavigationAgent has a path height property that can reduce the path point height by a fixed amount.

For navigation there is no “ground”, there is only navigation mesh, and yours is at that height. A navigation mesh always floats a litte but how much it floats depends on the baked voxel cell height and how uneven the ground is.

1 Like