Reputation: 67
I have randomly generated levels that consist of rooms. Each room has doors that are placed to connect these rooms. Each room can have up to 4 possible locations for doors. I use markers to place the doors on the walls, but I haven't added collision to these specific locations in the tileset. My question is, how can I add collision if there is no door or remove it if there is one? I want to control this from the code.
I was thinking about adding 4 layers that would represent collision for the doors and then just turning off or on specific ones of these 4 layers. However, I'm not sure if this is a good idea, as I'm new to Godot.
Upvotes: 0
Views: 657
Reputation: 1729
You can add collision directly to your tileset. In the documentation is a tutorial for it: https://docs.godotengine.org/en/stable/tutorials/2d/using_tilesets.html#doc-using-tilesets
I don't know how your tileset is build, but it should be no problem to add a tile without collision to the rest.
When placing the doors you could change the tile behind your door to the one without collision. All other wall tiles should be used with collision. Alternativly xou could also check if you simply can deactivate the collision for the tile instead of replacing it
To the detect the tile behind the door you can use Tilemap.world_to_map(pos) to get the tile at a specific position. You wrote, that you have markers placed already so you should have no problem to get the needed position.
Upvotes: 1