Proper Y-sorting for characters vs multi-tile walls (TileMapLayer + Node2D overlap issues)

Godot Version

4.4.1

Question

Hi everyone,

I’m working on a top-down game in Godot (like classic Tibia) and struggling with proper Y-sorting between TileMapLayer-based walls (built from multiple tiles) and characters like the player and monsters (which are outside the TileMap, in Node2D groups like Characters).

I’m trying to achieve a natural overlap where characters can walk behind and in front of tall wall tiles (e.g., 2x1 or 1x2 tilesets), depending on their Y position — essentially needing both X and Y consideration for sorting.

I’ve tried:

  • Splitting wall textures into more parts on different layers
  • Changing the Y-sort origin on the tiles themselves
  • Scanning forums/docs/tutorials — but each method breaks under certain conditions (e.g., corners, diagonal overlaps, or adjacent walls)

Is there a robust way to handle sorting between TileMapLayer-based objects and Node2D characters?

Ideally, a solution where characters properly sort behind/in front of wall assets, especially when those assets are built from multiple tiles and have offset origins (e.g. 16x16).
I’m thinking about something that works like or mimiks behaviour of same urgen x and y sort.

Till this point i’m pretty much sure there is no clean and easy solution for this because Godot draws tilemaplayers in whole rows and then the character on the same exact y-pos but lower x-pos is displayed over the tiles tiles that should cover him.
I belive that there is no such option to turn on that godot looks the same x and y axis to sort by but i hope that someone, somewhere in this world had similar problem and could fix it without writing own engine or whole huge plugin to godot :sweat_smile:

If anyone has faced a similar issue — or has a creative workaround — I’d really appreciate your insight!

example problem which is easy to fix but then it breaks somewhere else.

Also - here’s ss of walking by the wall (between the tiles).

In my ideal world godot, would treat the character right to object always above. As I said… sorting on both axes of the same importance would be best.

I don’t have a solution, but am curious if others do. I have the same issue with my isometric game.

When walking along walls, my character’s arm clips into the wall. I’m also having an issue where the y-sort behavior is different within a building depending on if it’s an internal wall or a top external wall. ¯_(ツ)_/¯

I’m curious if others have figured out solutions here. One hacky solution would be to just expand the physics collision layer to prevent your character from walking close enough to a wall to overlap. It’s not the best, but maybe better than visually clipping into the wall.

I also tried to find a solution to that, as I spent more time playing Tibia than I care to admit.
I couldn’t find any easy solution unfortunately, but during my research I stumbled upon a couple interesting projects that you might want to look into. In general, the term you’re looking for seems to be “cabinet oblique projection”.

Here I think they didn’t use the TileMapLayer specifically, but instead they recreated the world in 3D. Nonetheless, effect seems to be nice.

Here someone did exactly what you want, but in Unity. I’m not an expert in TileMapLayers, so I can’t judge if that would be possible to recreate in Godot, but you may give it a try and if it’s not possible - raise a proposal to have it in Godot.

Here someone posted a couple links to how Tibia projection works and how to draw pixel art in this style, may be interesting for you as well.
https://www.reddit.com/r/gamedev/comments/tcshfn/comment/i0h46ll/?context=3&share_id=wCixO_3W8R0Q2RZfVfG43&utm_medium=ios_app&utm_name=ioscss&utm_source=share&utm_term=1

Wow! Thank you guys for the response.

About time spent in tibia - same here :sweat_smile:

Thank you @wchc for tips and clues - i’ll look into it.

For now - the “recreating” tibia mechanics in my game is going quite nice, only this y/x sorting is killing me.

I’m in the point that i dont care anymore abut wrong displaying my scene but i have created very very small area where i tested my theory and I came to the result that is almost good :smiley:

It’s not perfect and after analyze the solution from unity i’ll reconsider my solution but so far this what I managed to do:

As I’m working on very old tibia assets they are something like this:
Image: 1

I did some redrawing and got this:
Image: 2

And those are vertical tiles like:
Image: 3

My thinking here is that if y-sort is prior - I need only tiles and tilesets that are vertical.
And for the day I’m working on it - I guess this is the only way that leads to the acceptable-ish result.

Of course, there will be some strange cases like “doorways” that some of it should be under the character when rest of it should be above and next edge case is when there are bigger monsters like demons od dragons that takes 4 tiles - not 1. But the thing that saves us is the fact that all characters always are shifted (like anchored) to the bottom-right corner so it never overlaps objects under and to the right of them what makes it possible to do. (I guess the tibia devs done that just because of the render-sorting)

So lets cut to the chase:
I cut the walls like you saw - then using 2 layers i created walls like here:
“legs layer”:
Image: 4.1

“body layer”:
Image: 4.2

And very different cut of doorway, created on even 3 layers because on very little fragment that should be always under the player I had to shift it a litte in drawing program compare to the original:
Image: 5

Final effect (shown on demon because the bigger characters are more problematic) with its only (found) problem is like this:
Image: 6 (Group)

The only problem (it appears only for a 1-2 frames) and i dont belive there is way to fix it:
Image: 7

As you could notice in the tileset ss - there is one alternative tile (for different y-sort origin) because without it there was one more problem on the ending vertical walls:
Image: 8

VERY IMPORTANT:
This solution took me a while to tweak back and forth the y-sort origin.
Finally the y-sort origin for my walls looks like this:
Image: 9

I know its not perfect - i know its annoying - i know its messy and weird… But it works and that my only solution I managed to invent after hours and hours of annoyance.

Hope that will inspire someone for better one or convince the GODOT team to enable both x and y sorting same importance. :slight_smile: (I’d like that)

(sorry for the image quality and format but im new member and cant add more pics :sad_but_relieved_face: )

1 Like