How to do Multi-Level sorting in 2D isometric tilemaps?

Godot Version

v4.5

Question

Hello!

I’m currently working on an isometric 2D game in wich multiple layers are involved. I want to have different layers involving the different ground levels and then layers involving the decorations on top.

The sorting of the different layers i managed to get it right by changing the y-sort origin of each layer to a multiple of the tilesize.

The problem comes when i try to place a player character that walks up and down each layer as it gets wrongly sorted. I am not sure in which way i can configurate it so that it can go up and down each layer and get properly sorted.

When standing in front it gets properly sorted

But as soon as i get on top of the tiles, the sorting goes crazy.

In the editor i have the configuration of the tiles and the nodes in this way:

The settings for the layers 1 and 2

And the player and player sorting nodes

I don’t know if this solution can be done through editor settings or through code…

Let me know if there is any additional information that would be helpful, thank you so much!

i think you have to work with the y-sort origin, whenever you change the layer you have to increase/decrease the y-sort-origin by the tile_size

1 Like

Thanks! That’s what i needed!

I did a simple script in which every time i go up or down the ysort origin changes accordingly

func updateYSortOrigin():
	for layer in tileMapLayers:
		layer.y_sort_origin = (layer.get_index() - currentPlayerLayer) * TILESIZE
	pass
1 Like