0 votes

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...

asked Jun 17 in Engine by Nailu (12 points)

Please log in or register to answer this question.

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.