• 2D
  • Properly using Y-sort with multi-layered isometric tilemaps?

Hello. I'm experimenting with an isometric grid system that features "height" layers on the terrain. I've figured out navigating the cells and shifting between heights without much issue, but there is one area I'm encountering trouble with, and that is getting objects to display behind the tilemaps where you would expect it to be obscured. In case it is not apparent, there are three levels of "height" here. As you can see, the tilemaps themselves are sorted just fine - all at the same position on the Y-axis - but the cursor is obscured by some degree depending on the height. At present, my code re-parents the cursor object to the height tilemap it's currently over and adjusts the Y position of the sprite and camera according to the height of the tile below, presumably causing the variable obscuring. I feel like I'm so close to what I'm trying to achieve but am misunderstanding something about the systems at play here. I've also tinkered with Z indices and parenting the cursor to the Y-sort layer it's in to no avail. I've checked just about every related online resource I could find and unfortunately there seems to be very little pertaining to my issue.

Am I going about this the wrong way? I'll admit, I'm still quite unfamiliar with Godot's node system, so any guidance would be immensely appreciated.

I would suggest putting everything under 1 ysort, you can use ysort childs under the main ysort if you have a need for containers to organize the scenetree.

@TwistedTwigleg said: Welcome to the forums @rakuBIT! Maybe this tutorial by @Stefan_GameDev will help? I had given it a look but wasn't ready to sacrifice the convenience of the auto tiling just yet, though I must agree it seems to be the most convenient way to handle isometric overall. (Nothing a custom level editor couldn't deal with, anyway.) And thank you for the welcome!

@Stefan_GameDev said: I would suggest putting everything under 1 ysort, you can use ysort childs under the main ysort if you have a need for containers to organize the scenetree.

This is what I had tried initially but it led to... this mess. Same thing occurred if I swapped the root Node2D for a Y-sort and kept the two Y-sort layers: Definitely doesn't seem to play nice with tilemaps of this nature.


Edit: Alright, so I tried turning all the tiles into props but I'm still more or less running into the same issue, so I'm kind of at a loss. Think I'll need to scrap what I've got and start fresh on this. Appreciate the feedback regardless, thank you both.

So that is likely because of the y-coordinate. You could circumvent that problem by displacing the maps from their 0,0 coordinates to 'fake' the y-coordinate for the ysorting to take place as you intend. However, with the grid having a single coordinate you may very well still run into issues with your cursor

And if you increase the z-index of the cursor? Or put the cursor in a canvaslayer. There are many options here.

Yeah, I had tried a number of methods using the Z-index, but it would usually result in the cursor being drawn above everything. The closest I've come is setting it to the Z-index of the layer it's on. However, this still ran into problems with the half-height tiles. All the fiddling about made my code a bit of a hassle to work with so I'll try it out some more once I've cleaned it up.

Z-index of the layer it is on + n. with n being a number between the z-index of the layer and the z-index of the next layer.

Also make sure that each layer is offset from the previous by a significant enough of a number so that you have enough buffer in-between them precisely so you can add utilitarian nodes between in the draw order.

I'd go for 1000, so layer 0 is z-index 0, layer one is z-index 1000, layer 2 is z-index 2000 etc.