Topic was automatically imported from the old Question2Answer platform.
Asked By
Macryc
Can someone explain how the Godot 4 collision avoidance with navigation agents system really works? I’ve been testing it and it doesn’t seem like it’s recalculating the path’s next step to bypass an obstacle based on the NavigationObstacle3d’s radius. I thought that was the deal but in my test project, when the navigation agent runs into an obstacle, it slows down and wriggles as opposed to walk around it even though there is plenty of room on the navigation region to do so… I’m assuming the system works differently but I can’t really infer how from the docs. Does anyone know?
It’s a little outdated (some naming has changed), but the gist is that you set your navigation agent’s velocity in _physics_process, but you don’t apply that velocity to your character. Instead you listen for the nav agent’s velocity_computed signal, and use the supplied “safe” velocity for your character.
Something like this (in this case “npc” is a rigid body):
If you want to actually have an static “obstacle” that affects the pathfinding you need to change your navigation mesh.
The pathfinding is only concerned with navigation mesh. If you still have navigation mesh below the obstacle occupied surface the paths will insist that the agent moves to a point that it can not reach due to the obstacle and the avoidance velocity pushing it back.
This is why the obstacles are only intended for moving and temporary obstacles as they do not change the navigation mesh used in pathfinding, they only change the avoidance velocities.