Hi everyone,
I'm trying to set up the navigation to work with TileMap in my game.
However, when I ask Godot to compute the navigations path (here in red) through fully walkable tiles (here in brown), this is the result I get:
Somehow it produces bent navigation paths and not straight lines.
I figured out paths where computed that way because the algorithm wants to go through tiles corners while avoiding edges.
My guess is that the different tiles navigations regions are not merged with their neighbours so I tried playing with the NavigationServer2D.map_set_edge_connection_margin() and NavigationServer2D.map_force_update() functions but nothing worked...
Thanks in advance for your help! 🙂
I found that this is still an open issue: https://github.com/godotengine/godot/issues/62115
If anyone found a workaround to this I'll be happy to hear from you!
Well, I haven't implemented this, but you could do it in two steps. First, get the navigation path as you already are. Then run a second algorithm doing "line of sight" tests on the resulting points.
From point 0, raycast to point 2.
If it succeeds (doesn't hit a wall or otherwise untraversable tile) raycast from point 0 to point 3,
then 0 to point 4, etc. until eventually the raycast is intercepted at point N.
Remove all of the points between 0 and N - 1, because you know you can make a straight line between them.
Then continue the process with N to N + 2, N to N + 3, etc.
This is a slow way of doing it, and it's just off the top of my head, but it would work. There may be a better and faster solution which relies on the properties of the grid map.
Symphonia
Do you want to walk along the actual tiles? In that case you could set up an AStar2 grid to match your tilemap. Or, I guess, if you want to move more freely, you could still use the AStar2Grid, just with a finer grid. When you create the AStar2Grid, you set every point to solid that corresponds with an unwalkable tile. I used this nice short tutorial to solve a similar problem.
For posterity: the solution is to not use the the Navigation layer from the Tilemap node but instead
- Add a NavigationRegion2D as a big area that includes all navigable areas
- Add the Tilemap as a child of this NavigationRegion2D. (Note: the Physics layer 0 will be used to bake the NavigationRegion2D)
- Click 'Bake NavigationPolygon' for the NavigationRegion2D node, or do it at runtime with bake_navigation_polygon()
--> Et voilà, a proper navigation mesh is created!
All is explained in details here
Symphonia This is great and thanks for updating.
What happens to nodes moving along paths if the tileset gets changed and the mesh needs to be rebaked?
© 2022 - 2025 — McMap. All rights reserved.