I'm using a NavigationAgent and a Tilemap with a Navigation layer to create pathfinding for my game. All the empty tiles in the enclosed region pictured are navigation tiles. Why is the navigation hugging the wall? I would like it to find a more optimal path, going in straight lines when possible. Any help would be greatly appreciated!
#Navigation not optimizing a straight line
5 messages · Page 1 of 1 (latest)
Update: For some reason, making the cells' navigation area smaller and increasing the NavigationServer2D's edge connection fixed this.
the path is going like that because the path corridor found with the TileMap navigation polygon cells by the pathfinding is not larger. What you see is a very common downside of using small square cells in pathfinding like the TileMap does. The possible shortest paths to the left, middle and right are all equivalent shortest paths for the pathfinding so it picks the first and not the most "beautiful looking" for humans.
in order to make a straight line with this small TileMap cells the pathfinding would need to add a considerable amount of otherwise pointless neighbor cells to the path corridor and merge them cause else it does not know that there is a line-of-sight for a shortcut. Something that is not done cause it costs a lot of performance for fixing something that is more or less an entire TileMap layout issues unrelated to the 2D pathfinding.
the simplest fix for this would be to use a combined navigation polyon instead of small cells cause that would fix the source of the problem which is the too small path corridor. Or use a physics raycast as a lineofsight check to straighten the path yourself in scripts. The navigation system has no access to physics so it cant do that.