I was wondering the same exact thing a few days ago and found this: https://github.com/FEDE0D/godot-pathfinding2d-demo
Basically what you do is create a tileset the alternative way (recommended on docs) which is to convert a scene into a tileset. So basically make a new scene and add sprites the way you normally make a tileset, then you can attach NavPolyInstances to each tile. Then in your map scene, make the TileMap a child of a Navigation2D and all the NavPolyInstances on the tiles will combine.
I’m pretty sure this works dynamically, so if you change the tilemap thought code it will update the navigation. However I have yet to figure out how to make the navigation avoid moving objects, such as a RigidBody2D.
I’ll test this as soon as I can
But, am I forced to put the tilemap as child of Navigation2D? Because I’ll have to update lots of paths to the tilemap, while it’s not related to navigation. Also, my world is made of rooms, and each room is made of a tilemap. Should Navigation2D be on top of all of them?
Zylann | 2016-03-21 18:09
All I know (haven’t had the chance to make my own TileMap yet) is that Navigation2D to a NavigationPolygonInstance is like a StaticBody2D to a CollisionShape2D, but maybe a dirty little trick such as changing the root node of the scene from the usual Node2D or Node, to a Navigation2D might work… maybe.
batmanasb | 2016-03-21 18:16
I just tested with two tilemaps in the example, and it works! This is wonderful! I love this game engine <3
Zylann | 2016-03-21 19:17
Awesome! But just to clarify, what works? What exactly did you do? I’m curious
batmanasb | 2016-03-21 19:20
I just wanted to see if having multiple tilemaps works too, and it does
But now, I realize that my levels are built the opposite way: instead of placing tiles AIs can walk on (those with NavPolys), I usually place tiles that can’t be walked (walls). I even have one tilemap for the ground, and another for walls because they are blended together (so I don’t have to update wall tiles if I change the ground).
I wonder how I should adapt the example to my game. Place invisible tiles on the Walls tilemap just to build the navigable part?
EDIT: this is discussed here: Need to occlude NavigationPolygon set in TileSet at runtime · Issue #3821 · godotengine/godot · GitHub
Zylann | 2016-03-21 19:29
Multiple TileMaps is less efficient, but if that works for you then that’s fine. But wait, I’m not sure how you are building the the navpoly. You can’t place walls to block off a navpoly, blocking off navpoly only works if you draw shapes inside shapes in a single NavigationPolygonInstance. I think a good approach would be to just add square NavigationPolygonInstances to the floor/ground tiles or make another TileMap and then place NavPolyonInstances over the ground, and nothing on the wall tiles.
batmanasb | 2016-03-21 20:08
What I’ll do for now is to dedicate a tilemap to nav polys, or have two versions of ground tiles (one with, one without). Actually it would be easier if I could build navigation with occluders instead of “walkable” polys.
Zylann | 2016-03-21 20:39
I don’t think you can build navigation with occluders. Only way of occluding navpolygons is when you draw polygons within polygons in a single NavigationPolygonInstance, which wouldn’t work because each tile has a separate NavigationPolygonInstance. At least not yet…
batmanasb | 2016-03-21 21:00
can we add something like floyd-warshall on godot?
c21james | 2019-08-25 14:30