Godot Version
godot4.5
Question
I have a Zelda-like that I'm working on and I'm trying to set up y-sorting between the player and props like fences and rocks and such. currently, this is how my scene is set up:
MAIN
_player(parented to main)
__player sprite(parented to player)
_level(parented to main)
__navigation region(parented to level)
___tilemap layers(parented to navregion)
EVERY NODE listed has y-sort enabled, and the player sprite and relevant tile map layer are on the same z index, as well as having z as relative turned off. despite this, the player appears in front of the tiles on this layer regardless of it’s position. why is this?
Hello! I can’t be 100% sure on this but Godot Engine is very responsive to the order your nodes are in.
If your player node appears to be the first in the order and if your level node appears to be the last in the order then Godot Engine probably tries to render player first because he is on top of the order.
I can’t be 100% sure on this again but such thing is very painful during the development of “Multiplayer”. Specifically, when using node “MultiplayerSynchronizer” Godot Engine really cares about if that node is on the top (first) in the order or is the last.
interesting, I’ll mess with that and see if I can drum up a solution
1 Like
What’s the local transform of the Sprite? Are the TileSet’s texture origins or Y-sort origins modified?
Usually, it should be enough to enable Y-sorting for all parent nodes: MAIN, level, navigation region and tilemap layers need to have it enabled, player depends if you want to use the player’s local transform or the sprite’s. Then the tiles’ Y-sort origins need to be set correctly, so their values are comparable to the player/sprite.
By default, the player should draw behind the tilemaplayer, so there definitely is some sorting happening. I know you said you have it enabled on every node, but it still seems like either level, navigation region or the tilemap layers have it disabled. (If they are positioned at (0, 0), the player would only be drawn behind if its global position.y was lower than 0, which is above the default screen space)
Here’s a good explanation of using Y-sort and issues that might arise:
If that’s not enabled, then simply the order nodes are listed in the tree will affect draw order I think (root first, children next in order, grand children and so on). Tutorial above covers that as well.
Finally, you have canvas layers. Stick anything on canvas layer 1, and it will draw in front of anything on layers 0 (the default) or negative numbered layers (which appear behind the default layer.