Path calculated from Navigation 2D does not have a "clearance" area

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By immccc
:warning: Old Version Published before Godot 3 was released.

Hi,

I am facing the situation that, when a path is calculated to traslate a sprite avoiding non navigable areas, sometimes those paths are skimming those areas, so the sprite that goes through is partially inside once approached to that zone.

After checking the documentation of Navigation node, I have found nothing that gets the closest path to reach a point taking into consideration the sprite size, or a predefined clearance area defined as a box or rect.

Here’s a draft of the situation and what I’d like to have: Imgur: The magic of the Internet

One might think that a solution would be to create bigger non walkable areas, but consider a rectangle clearance areas: That way, It could happen that a valid position to be reached by a path is not eligible for the path.

Any ideas? Thanks in advance.

:bust_in_silhouette: Reply From: Zylann

I have two ideas:

  1. Change the size of the colliders used for pathfinding (on a different layer) so that they take the size of agents into account. Upside: little to no code changes. Downside: you would have to do that for every agent size.

  2. Process the path you get by moving it along its normals to try to fit the agent, using raycasts and shape casts to predict how much to move the points. Upside: once done, it works for any size. Downside: more difficult to get it right, there are corner cases.

If there is an actual general solution to this, it could be worth it opening a Github issue to ask for an agent_size parameter maybe.

Thanks for your answer :slight_smile:

Unfortunately seems that there is no a high-level to do that. I thought about raycasting as well, but it is not the most efficient approach in my opinion as it adds extra calculations everytime the node that follows the path is positioned.

Opening an issue in Github is a good idea!

immccc | 2016-12-19 19:13

You can add critical Areas on the map that activate the detections on enter to reduce constant checks.

eons | 2016-12-20 17:58