Path generated by NavigationAgent2D makes no sense (TileSet Navigation Layer)

Godot Version

4.3.stable

Question

I’m using a TileSet in a TileMapLayer with navigation (visible in screenshot), and a NavigationAgent2D.

Can someone explain why the path isn’t a straight line to the character, and instead take this weird detour?

Edge Centered:

Corridorfunnel:

That is the path corridor caused by the tiled cell layout. An optimized navigation mesh wants to span from actual “wall” to “wall”. That is usually also the result that you get when you bake the navigation mesh with a NavigationRegion2D or the NavigationServer2D. You could bake your Tilemap with a region and disable the TileMap build-in navigation.

The TileMap build-in navigation can not handle any of that. A core flaw of grid cell layouts when used with navigation mesh is that there are multiple versions of ugly cell corridors for the same target when going diagonal. Without a lot of extra post processing and line of sight checks that is the best that tiles can do with navigation mesh. Hence why many projects that want to stick with tile cells fall back on the more simplistic and robotic point based navigation like Astar2D and AStarGrid2D.