2d tilemap topdown game, sorting order problem.

Hey everyone, i have been working on a simple topdown pixel art game with procedural generation made from prefab rooms. All the rooms contain a grid with 4 tilemaps, background-wall-decor-decor2. I have been struggling with making the character appear above walls that are on the top side and behind walls that are on the below side.
Right now what i have come up with is having the character’s collider on its head so that the legs can go beneath the below walls, this approach is working just fine except for the part if i want to add walls to the middle of the room. I all include screenshots to make things more clear. How can i make this work?
I tried making the sorting depended on the Y axis in project settings but that introduces other problems like glitchy looks in the background layer. Is there a smart way of getting this done?

You could customize the colliders of the walls in the Sprite Editor.

What happens when you have the wall’s collider not include the very top of the wall and instead exists only at its base?

For sorting, you should look at this:

It’s not totally clear to me from the screenshots where the sorting problems are: expectation vs. reality. To get tiles to sort individually against a character well, it usually requires
(a) pivot point on character’s sprite (I assume this is a 1-sprite character?) to be put near the feat
(b) character SpriteRenderer using Pivot mode
(c) Tilemap set to Individual Mode rendering, and pivot points set on the sprites of the tiles near the base of the sprite
(d) y-sorting (looks like you’ve done this) using Transparency Sorting Axis of (0, 1, 0)

As it is right now, there is no sorting problem but if i add a single tile of wall in the middle of the room, there will be a problem. because to make it seem like the character is infront of the wall, i use 1 level of “wall” and 1 level of “decor” beneath it.

I didnt quite understand what you mean by this, In the first screenshot, there are 2 different tiles for the wall, the lower is in the “decor” tilemap and the top is actually the “wall” tilemap and only “wall” has colliders so i can create the illusion of depth that way.

Its not 1 sprite actually it has quiete a few animations on it but i assume i ll just edit every piece’s pivot to the feet and that should work fine. I ll try again that way and see if it works then post here either “working” or “still have a problem”…

Re: colliders. I was suggesting addressing this…

…with changing the collider. You can customize colliders per-sprite by using custom collider. Your wall sprites, right now, create a collider for the full sprite and/or tile. I’m suggesting you change that collider so that it doesn’t create collisions at the top of the sprite. This would mean that you do not need to shift the collider on the character upward away from the feet. You will get the same illusion of depth (the character can walk behind the wall) but with more precision and not awkwardly changing character collider.

In pic, you can see that this tile gets its collider from the sprite. By giving a custom physics shape (see link above) you can more precisely control where the collider is per-sprite.

Hold up, you want to use a Sorting Group.

Sorting Groups are very useful for exactly this situation - where you want several SpriteRenderers to sort based on a single point (the feet). Basically if you give your character a parent gameobject that is positioned at the feet and put a Sorting Group on it then the child objects will sort based on the parent’s position.

that’s great, i ll give that a go in a bit.

That also seems very very useful, i had no idea that was an option that’s why i didnt quite understand you earlier. I ll try this too and update my post accordingly. TYVM!

out of the box tilemaps dont facilitate making walls like these, the tiles on the top of the wall need to have the pivot point on the bottom of the wall, this is really cumbersome to make because the pivot point on each tile depends on the height of the wall