0 votes


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: http://imgur.com/a/zhraE#2QjeyMp

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.

in Engine by (24 points)

1 Answer

+1 vote
Best answer

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.

by (27,962 points)
selected by

Thanks for your answer :)

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!

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.