How to avoid textures from tilemaps overlapping eachother

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bl

Hello. I’m currently working on a procedurally generated 2d game.

I want to procedurally generate the playable area where the player is surrounded by rocks, but the rock-textures are of different sizes.

The rock textures are 1x1, 1x2, and 2x2 tiles. Currently the different sized rock-tiles overlap eachother. It seems that even tho I set the tiles collision to 2x2, the placed tile is still only 1x1. Is there a way of making the tiles not spawn if it collides with another?

I’ve added a screenshot to better display my problem.

:bust_in_silhouette: Reply From: exuin

Tilemaps combine all of their tiles’ collision shapes into one big collision shape. So just check if there’s a shape at a certain point using Physics2DDirectSpaceState!

Alternatively, you can just check if there’s a 1x2 or 2x2 tile right next to the tile you want to place the new tile on.

Thank you for your answer, but I’m still struggling.

So I tried to use Physics2DDirectSpaceState with a raycast to detect collision, but it seems it only works inside the _physics_process. My function for populating the map with tiles works outside of the _physics_process.

I like the idea of using the tiles collision to decide whether a tile should be placed or not, because it can be reused for different tilemaps. But I may just have to hardcode the size of each tile and then make the code decide which tiles to skip.

bl | 2021-03-14 12:24

Yeah maybe the second method should be used in this case

exuin | 2021-03-14 14:40