I’m new to using the Godot engine and currently developing a 2D game. For context. I have the following:
Main Scene
→ Tilemap
→ Character
The tilemap has a few layers and one is called y-sort, which contains specific objects that will create a certain scenario.
Scenario:
The player will be shown being at the back of the object when he goes at the back of it.
Now, I have y-sorting enabled on the following:
Main Scene
TileMap
Y-sort Layer
Player
I’ve set the position of the y-sort and also added collisions to the object, but when I run the project, the player just goes on top of the object, not behind. I’ve tried testing out z-index changes, but nothing happens.
You say you have a tilemap layer called “Y-sort”. What do you mean by this? There should be an option in the TileMap node that y-sorts tiles globally, and if that’s set then it should work. If that’s what you’re doing already, then I don’t know how to help.
I watched a few tutorial vids on youtube about y-sorting and it says to both set the tilemap and the layer with the objects’ y-sort on. That’s what I did ![:smiling_face_with_tear: :smiling_face_with_tear:](https://forum.godotengine.org/images/emoji/twitter/smiling_face_with_tear.png?v=12)
I have the same issue have you managed to fix it?
I sorta did. Bear with me on understanding what I type.
The objects are in a tileset. Lets take a table as an example. In that tileset, this table is 2x2. Previously, I made the table into 1 tile only. Then the problem I had above got me stuck.
What i did is put them in as is, so I made the table 2x2.
The top part of the table is on a higher layer than the bottom part.
Dont forget to add collisions and to extend the collisions on the TOP PART so that it kinda reaches the collisions of the BOTTOM PART.
Enable y sorting for this layer btw. I can show it to you if you want. Let me know cause Im super bad at explaining things lol.
and to add more for reference, the layering is like this;
bottom part of tile is on layer 0
player is on layer 1
top part of tile is on layer 2
So if i understood correctly you basically separated the table into 2 different tiles that’s on 2 different layers to give off the effect of y-sorting.
Idk if it would work for me because im trying to do a fence that’s basically a wall and i’ve gotten y-sorting to work in previous projects but for some reason now it doesn’t in this new project.
But you’ve given me a different idea that i think would work so thanks. I think i’m just gonna do 2 different tiles that’s pretty much like what you did one type of fence that appears on top of the player and another below the player.
Since the player won’t be able to get around the fence anyways i think this will work.
Thanks for the idea.
I tried it and it worked.
To ensure your player character appears behind objects in your y-sort layer, follow these steps:
Ensure Y-Sort is Enabled: Verify that Y-Sort is enabled on the parent node containing both the player and the objects.
Correct Node Hierarchy: Make sure the TileMap, Player, and Y-Sort layer are correctly placed under the parent node.
Y-Sort Order: Check the Y-Sort setting on the TileMap, Player, and Y-Sort layer. Ensure the player’s Y position is being updated correctly relative to other objects.
Here’s a concise example:
Main Scene Setup:
Main Scene (Node2D/YSort)
TileMap
Player
Y-Sort Layer (Objects with Y-Sort enabled)
Player Script:
Ensure the player’s script updates the Y position correctly:
func _process(delta):
$YSort.y_sort_mode = YSort.Y_SORT_MODE_POS
$YSort.sort()