- Edited
What I'm trying to do:
I'm completely new to Godot (4), and I'm prototyping a top-down 2D game. I have a separate Tree scene with different parts that can be set in the Inspector, such as Roots, Trunk, different levels of Branches and so on. I want to give these parts different fake "heights" in the game, so that the Roots are Y-sorted with a different origin than the Branches in the crown of the tree.
For tiles in a Tileset, I figured out Y-sorting to reasonable satisfaction, because I could set the Y sort origin under Layers in the Inspector. However, this option does not seem to be available for just any Node2D or sprite. And in any case, I want to be able to build large trees with branches at different heights, that should have their Y sort origin at different points and preferably controllable by script.
What's happening:
In the screenshot below, you can see how my Grass Blades are Y-sorted correctly with respect to the Player, thanks to them being part of a Tileset. For the Tree however, something unexpected (at least to me) is happening. The Roots and the Trunk are being drawn below the Grass Blades (and the Player), but the Branches are actually being Y-sorted! You can walk behind the branches, and they are partially being drawn below the Grass Blades, which is a good start.
However, the cutoff for in front and behind is also wrong. You can see this with how the the Grass Blades are partially drawn over the orange branches - the cutoff appears to be just about at the top of the Trunk (although this doesn't change if I scale or move the Trunk sprite).
Further information:
I have the Tree scene organized as a Node2D with Y-sorting enabled, and everything else as children of that Node2D. I've tried manually enabling Y-sorting for the children, but that seems to have no effect whatsoever, so I'm leaving it off for now.
Any thoughts or pointers would be greatly appreciated! I'm not necessarily married to this way of creating the tree Scene, but I do want to avoid making it a Tileset if possible.