Hello,
I am trying to use the new navigation API, but it's not working so well.
I've created a simple crowd context, with 16 agents moving to a point together. From what I understood, I need to first set a target velocity, wait for the NavigationAgent3d to compute a safe_velocity, and then use it for the actual movement. However, it's not working so well, and I don't understand how this interface is supposed to be used.
Here the code I was using :
extends CharacterBody3D
@onready var navigation_agent: NavigationAgent3D = $NavigationAgent3D
var safe_vel: Vector3
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
var target_vel: Vector3 = navigation_agent.get_next_location() - self.global_transform.origin
navigation_agent.set_velocity(target_vel)
await navigation_agent.velocity_computed
velocity = self.safe_vel * delta
move_and_slide()
func _on_navigation_agent_3d_velocity_computed(safe_velocity: Vector3):
self.safe_vel = safe_velocity
With this setup, the movement of the agent is quite erratic, they are moving very slowly, suddenly very fast, and then once the path is completed, sometimes don't stop and fall off the edge. Any ideas what causes this ?
FYI I did not touch any default parameter for the NavigationAgent3D, I only checked the avoidance_enabled
to be true.