The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+5 votes

So, I have the following setup:

and I get this in the game:

How to make the character appear behind the tilemap, depending on its Y sorting, but in front of a torch?
I've spent the whole evening, trying to accomplish that, no luck so far. Is that even possible?

in Engine by (198 points)
edited by

1 Answer

+6 votes
Best answer

I'm still figuring out sorting myself, but I think that adding the torch nodes as children of the walls tilemap (assuming the root node of the torch is in the same position as the torch sprite), then the walls tilemap should sort the wall tiles, the character, and all the torch nodes based on their Y position. Although, I can see a small issue where the Y position of the wall tile matches the wall tile, causing the wall to be on top (maybe). This should be fixable by moving the torch down a little (by 1px or even less).

by (855 points)
selected by

Now the node setup is this:
enter image description here

and...the issue remains :D

I've tried some more variations of the nodes placement in the tree and none of them worked as I wanted. In some setups, the Y sorting didn't work, but the character was drawn in front of the torches. In the other setups, everything was the other way round. Looks like it's either impossible(hope it's not) or rather tricky to achieve.

I think you misunderstood me. I'm assuming "torches" is basically a folder node. Inside you have instances of torch scenes (for example, something like a Node2D with a Sprite and a Particle2D as children, similar to that character instance). See how you don't have a "characters" node and instead just made the character instance a child of "walls"? So what I'm saying is that you should get rid of the folder node "torches" and add each "torch" instance as a child of "walls", exactly as you did with the "character" instance. Because the way Y-Sort works (in the TileMap node and in the Y-Sort node), is that it orders its direct (ex: the character's root node is the direct child of the "walls" TileMap node) children based on their Y position.

Edit: just to clarify, right now the Y-Sort is sorting the "torches" folder node, instead of the torch instances inside of it

Oh, yes, I did misunderstood you. I've got rid of the folder node:

The Y sorting kinda works, but not the whole character sprite is affected:

Now I think you just need to mess around with the position of the root nodes. Figure out which part of each root node is the origin aka position (0,0), and move the parts around while keeping the origin at position (0,0). This is the part I'm even less experienced with, but I think some nodes have the origin on the top left corner of the node (probably KinematicBody2D), and others such as Sprites might have the origin at the center. Also, I think tiles are center, but I'm not sure.

So you basically just need to move the contents around until it looks right. I think the easy way might be to simply change the Y offset of the torch sprite (to about -10) and then shift the children nodes that amount as well. But I never tried this myself, so I can't know if that will work. But the other option is to add a Node2D as the parent of the torch Sprite, and simply change the position of the Sprite, and this way the children will move as well (unlike with offset).

But yeah, then you're basically done!

I messed around with the origins and offsets and it's working as it should now. Thanks for seeing me through!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.