Pathfinding goes long way around gap in one direction but not in the other

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thenewandy

Hi, I have a fairly simple project with a character that just finds a path to where the mouse is clicked and follows it. There are two NavigationPolygons to create a scene that is mostly open with a roughly square shaped hole in the middle. When I find paths from A to B they are good, but paths from B to A are very indirect.

Here is a video demonstration with “Visible Navigation” turned on (where “A” is left of the house, and “B” is right of the house):

I’ve tried messing with the polygons to make them overlap or not overlap.

Happy to post code if needed, but it is roughly the code you would expect for a complete beginner to Godot (using a NavigationAgent2D on the character, and the set_target_location() and get_next_location() methods on it to figure out where to move_and_slide() to).

Ok, I can kind of fix it by adding extra vertices to the navigation polygons around the corners of the “hole”. Is this what is expected?

thenewandy | 2023-02-20 23:48

:bust_in_silhouette: Reply From: smix8

Glad you fixed it. In the original issue / video your navigation polygon was broken cause the debug visuals are facing in the wrong direction.

This happened properly due to the hand drawn polygon having some positions / edges overlap or duplicated. This in turn makes the NavigationServer merged the wrong navigation polygon vertices and edges together resulting in this long walkaround.

Thanks for the help. Can you explain what you mean by the visuals facing the wrong direction? I am rewatching the video and don’t know what would look different if it was correct.

thenewandy | 2023-05-06 09:44

Those debug half-circles are for edge connections and they face in the other direction when they are correct e.g. the open side faces inward along the edge, not outward.

smix8 | 2023-05-06 09:56

Thanks so much

thenewandy | 2023-05-06 09:58