How to make a sprite go behind another sprite using YSort?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bodicpen

I’m trying to learn Godot and this is my fourth week now so I’ve decided to experiment with a project inspired by the game Don’t Starve. It’s a 2D Isometric game. I’ve converted the trees into a tileset for easy placing but if my player tries to go behind it, it appears that my player is just going up rather than going behind the tree. I’ve put the Player scene and the trees tileset as a child of a YSort but it still doesn’t work. Take a look:

The player looks like he climbed on the tree

here’s the link if in case you can’t see the picture: 2 hosted at ImgBB — ImgBB It’s from

Now I know that this is probably because the Ysort still reads each tree as a whole sprite but is there some way I can make it so that if the player’s Y position is higher than the trees’ base, the trees will then load in front of the player to make it look like as if the player is behind the tree?

:bust_in_silhouette: Reply From: rustyStriker

this video explains all there is about the Ysort node(or at least all you need in order to use it)

See my answer, I think that he wants to sort the player with the tiles of the TileMap. The video explains how to sort just sprites.

rgzr | 2019-01-19 18:20

Hi! I’ve figured it out. check out my answer! Thank you for answering!

bodicpen | 2019-01-20 04:44

:bust_in_silhouette: Reply From: rgzr

What we achieve placing both the TileMap and player as direct children of Ysort is that when the player Y position is higher than the tilemap Y position, our player is drawn above the tiles, but this is using the “general” TileMap Y position value, not the individual tiles Y value.

What I understand you (and also me) want to achieve is sorting our player along with the tiles of a TileMap. In version 3.1, there’s a “Y Sort” option on the TileMap, but it (again) just acts as an YSort, sorting only the direct children of the tilemap (not its tiles).

I think that a solution is to place the tiles manually as a sprite as a child of Ysort, but that is defying the purpose of TileMap I think.

Hi! I’ve figured it out. check out my answer! Thank you for answering!

bodicpen | 2019-01-20 04:44

:bust_in_silhouette: Reply From: bodicpen

I’ve figured it out. After looking at the isometric game demo of Godot engine, instead of putting the ground tilemap, trees tilemap, and the player under the child of the YSort, I removed the YSort, and I’ve put the player as a child of the trees tilemap instead and enabled its Ysort property.

i know this is necroposting, but adding the player (kinematic body in my case) as a child of the tilemap doesn’t work. The player will still walk over the tilemap regardless of its Y position.

thatreshaad | 2020-03-30 08:53

I find the same thing. Not sure how to fix it.

cammil | 2020-06-21 09:51

Play with the tile origin a little, that helped me.

k3nzngtn | 2021-04-22 16:35