Join colliders vertically in tilemap

Hi, I have a procedurally generated tilemap. The sprites I use don’t have the perfect squared collider, I’ve adjusted the physics shape of the collider so the player can walk into them and look more 3D. This is a editor screenshot. I’m also using composite collider 2d

My game is a roguelike, and small bullers can pass thourght the colllider holes, something that shouldn’t happen.

Is there any way to change the physics shape of a tile at runtime? I want to have something like this: (picture is an edit):

This way I have the depth illusion and bulltets won’t go thourght the holes.
I’m not even sure if this is the correct approach, I hope you can help me.

Could you share what kind of Tile you are using for your collider Tiles?

You may consider using the Rule Tile from the Tilemap Extras package. This will allow you to keep the visuals but change the collision shape to the full Grid Cell depending on what kind of neighbours it has.

Some documentation here: 2d-extras/Documentation~/RuleTile.md at master · Unity-Technologies/2d-extras · GitHub.

I’m really using any tile, as I said everything is procedural, as I don’t want to create and configure tiles for every spritesheet I have, I made an scriptable that converts a sprite array to tiles, but these tiles are stored in the scriptable, they aren’t in the project, they aren’t used in any tille palletes. The code looks likes this:

//Collider tiles
        wallTiles = new Tile[wallIndexes.Length];
        for (int i = 0; i < wallIndexes.Length; i++)
        {
            tile = ScriptableObject.CreateInstance<Tile>();
            tile.sprite = theme[wallIndexes[i]];
            wallTiles[i] = tile;
        }

        //Non collider tiles
        floorTiles = new Tile[floorIndexes.Length];
        for (int i = 0; i < floorIndexes.Length; i++)
        {
            tile = ScriptableObject.CreateInstance<Tile>();
            tile.sprite = theme[floorIndexes[i]];
            floorTiles[i] = tile;
        }

I’m not sure if I can use rule tile with this method

You could create a RuleTile procedurally as well, using ScriptableObject.CreateInstance<RuleTile>. You will need to do some additional work to add in the Rules programmatically. This would involve adding TilingRules to your RuleTile to figure out the Sprite and the Collider Type based on the position of the RuleTile and its neighbour.

Alternatively, is it possible to check whether your wall tiles have neighbours when you are procedurally generating your level? If you are able to, you can use Tilemap.SetColliderType and change the Collider Type to Grid to take up the full cell for those positions.

Thanks for the answer! But I can’t do that, I’ve already tried, I eventually created a new tilemap that has the collisions, this tilemap has a ruletile that contains 4 sprites, that have the physics shape of the colliders I want, I don’t like the solution but it works for now.

The other reason why I didn’t use rule tile, is that it doesn’t work for my tilemap, my code generate the wall sprites based on the neighbour of the floor tilemap, ruletile can’t look at neighbour on other tilemap (and that makes sense), I’ve been playing with tile rules all the day but it seems it can’t work, look at this:

They are the same rule tile case (only neighbours in the left/right side), both are the same, the difference is that one has floor down and the other has floor up, but rule tile don’t know this, it can’t know it, rule tile is awesome for doing the interior, but not borders of tilemap. I know I can create and scriptable rule tile and add the floor tiles to it, but I can’t have all in one tilemap as the floor is in a sorting layer below the player and the walls one is in the same sorting layer with y axis sorting. Furthermore, for every new theme/spritesheet I want to use, I have to duplicate the rule tile asset and manually assign every sprite, too much work.

But I’m still looking for more scalable ways to do the tilemap painting and collider generation