So I know how to set up the tilemaps for everything to be able to navigate it. But how can I set up only certain objects to travel only in certain type of tiles? For example ships only on water and people only land.
Defining tilemaps for travel. Ships on water, people on land tiles.
If I keep 2 tilemaps separated for water and land tiles can I somehow use script functions to only allow certain classes to enter them?
You can have them in the same tilemap if you want. You just need to use collision shapes, and then test the type of tile the object is touching. I think the function "get_cellv()" will help you.
- Edited
You can use get_cellv but I think if there are large bodies of one tilemap like water adding a group and running a check on that with the collision will work just fine, seems you could do either one. Other people will probably be able to explain in better detail to me which one is more efficient, if it's all 2D though you won't have too much to worry about.
In this post I made there was a person who went into a lot of detail in how the index checks worked and I also have some code there that shows you how to do checks for which type of tile you're colliding with.
- Edited
Thanks for the answers. So Godot can differentiate between different tiles in a tilemap that's good to know.
I'm just a bit worried it will effect pathfinding, since the ships won't know of "land" in advance and will try to pathfind a straight way through land first if the destination is between land and water.
I won't have procedural generation so I had another thought if I could just paint the borders of land with some tool.
Is there some way to do this in Godot? Mark an encapsulated area as a "no go zone" .
Edit: I guess I could just do a huge area2D or staticbody and add collision on it. I would guess pathfinding would also work with it.
If you check out the tilemap editor you will see that there are collision and navigation tabs, the collision tab does exactly what you think, you can draw the collision for that tile and it will replicate itself when you paint that into the scene. Just a heads up when it comes to navigation the tilemap is extremely fussy, you can also check out what index the tile belongs to by clicking the yellow symbol at the bottom right of the tile editor window.
- Edited
That's a decent solution too, didn't even cross my mind. Just make a new "Borders" tileset with collisions and add them to the edges of land. Sounds quite elegant.
I'll probably go with that.
Thanks ya'll.