+1 vote

I'm new to game development and this might be a very basic question but I couldn't figure out how to pathfind around objects I've searched for a few hours but the tutorials I found just use a single TileMap.
I'm trying to do a 2d RTS game and currently have a TileMap as well as units that I can move around using Navitagion2D#getsimplepath(). The tiles have NavigationPolygonInstances and the units are able to pathfind around them. I also use moveandcollide() and a CollisionShape2D per unit so they bump off each other (not perfect but at least they don't walk into each other).
Now I'm having issues with spawning static objects like trees or buildings and having the units pathfind around these. I tried adding them as tiles but then a unit can't walk behind a tree. I.e. they should only collide with the bottom of the tree and otherwise be able to walk around it. Since the TileMap is on the lowest layer, the sprites of units will be above the tree which looks odd. I also tried spawning these objects like I did with the moveable units but then the pathfinding won't work, units just walk into static objects and slide off of those instead of pathfinding around. I've also tried adding another TileMap for objects as a second layer. But if the object TileMap is below the floor TileMap in the tree, then the collisions are ignored, if the object TileMap is above the floor the collisions work but the objects are not visible. It would be a very nice solution if I could simply make the second TileMap visible while the collisions work because then I could reuse the code for the first TileMap :)
I've also tried adding a NavigationPolygonInstance to the Navigation2D which contains the TileMap but those polygons didn't seem to have any effects...

in Engine by (13 points)

1 Answer

0 votes

I know this one was raised in January, but im facing exact same problem.
Trying 2 tileMaps. One with navigation area and second with obstacles. I cant find a way to get the pathfinding to work with this. Not mentioning the fact that it seems like there is no support for multi layer tileMaps

by (14 points)

I keep the tilemaps out of the Navigation2D entirely and create a simple (invisible) tilemap child to Navigation2D at runtime that combines collision and navigation objects from both tilemaps.

Seems like child tilemaps should pool that information under Navigation2D. That's what the documentation entry for Navigation2D indicated would be the case.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.