NavAgent not reaching target

Godot Version



Hi All!

I’m trying to use NavMesh and NavAgent to control some RigidBody3D objects. If I don’t have avoidance enabled on NavAgent the object is reaching it targets correctly but as expected the objects are bumping in each other. However when I enable avoidance the objects are avoiding each other however they’re not reaching the target location and stop. It’s clearly visible in the screenshot below where red solider has avoidance disabled and the blue one has avoidance enabled. They should be in line and even debug line shows that the object is far from the target. However the signal navigation_agent_3d_target_reached is fired in both cases.

I’ve tried multiple setting for avoidance but nothing seems to work. Is this expected?

Current avoidance settings:

There are 2 different things to unwrap here.

The first is the target position and tracking.

It is controlled by the target_desired_distance on the NavigationAgent. At this distance to the target the path will be considered at its end. If the target position is invalid to reach, e.g. because it is set to far away from the navigation mesh, it will not be used, instead normal path movement controlled by path_desired_distance will go until the last path point is reached.

Now the problem in current Godot 4.2 (or older) is that this property check has a bug so the target_desired_distance does not really work when it is lower than the path_desired_distance. There is a PR that fixes it.

The second is the avoidance.

The time_horizion_agent and time_horizion_obstacle properties control how long, in seconds, the velocity needs to be safe to use. This means the agent will try to not use any velocity (direction) that will collide in that time window. If that is the only option, e.g. the target position is blocked by an avoidance object, it will instead slow down its velocity to still not collide in those x seconds.

This means in general you want to keep those time horizion values as low as possible to not have your agents slow down too much. The value should still be high enough to avoid agents picking velocity directions all the time that become invalid quickly as that would make them look jittery.


Thanks for the fast response!

Based on this I’ve changed the path_desired_distance target_desired_distance parameters and that kinda fixed the problem. However I’m still not sure why this affects the behavior only when the avoidance is enabled. If everything is set to default and avoidance is enabled even if I have a single NavAgent and NavMesh in the scene the object doesn’t reach the target. It only reaches the target when avoidance is enabled. I guess that enabling avoidance somehow affects target_desired_distance and path_desired_distance ?

From your screenshot I think you are using the wrong avoidance mode. Please check the documentation of the “use_3d_avoidance” property and the general doc for the two avoidance modes. The 2D avoidance is for movement on a plane in both 2D and 3D games while the 3D avoidance requires movement in all 3 axis and is for e.g. space or underwater games. Your agent likely wants to move into the ground but is blocked by physics collision.

Thanks for the help, will read some more docs. But looks like setting the right parameters solved the problem. Not as easy though as minor changes sometimes break everything. :sweat_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.