I’m trying to debug why avoidance doesn’t seem to work with Godot’s 2D navigation tutorial example code.
I’ve updated the example code to use set_velocity()
. This required changes in two places. First, in _ready
, I need to hook up the velocity_computed
callback:
Then, in _physics_process
, I need to call NavigationAgent2D
’s set_velocity
instead of move_and_slide
so that it can be used in the collision avoidance algorithm.
After the collision avoidance has been computed, the new velocity is sent to update_movement
via the velocity_computed
signal that was set up earlier at the end of _physics_process
and we can move correctly using the new velocity.
Important things I noticed:
- The
max_speed
property will clamp the magnitude of the velocity passed toset_velocity
to themax_speed
value.