Hello,
I have an off y-sort issue. I have the following object set up.
StaticBody2D
AnimatedSprite2D
CollisionBody2D (segmented shape 2d)
CollisionBody2D(segmented shape 2d)
CollisionBody2D(segmented shape 2d)
CollisionBody2D(segmented shape 2d)
The collision bodys outline the base image size.
If I enable y-sort and set a z-index on t he animated sprite and on the static body then I can walk behind the crates and be hidden by them, but if I walk infront of the crates then I drift into the crate image.
I’m trying to get to walk behind the crates and infront of them.
I have the player set to z-index of 20
The static body and animated sprite are z-index of 10
Any suggestions?
Thanks
Make sure all of the nodes you want to be able to swap draw-ordering have the same z-index and y-sort enabled. The node that contains your player and the other objects must also have y-sort enabled.
Also make sure the objects’ origin y-values (position.y) correspond to the exact point where you want their ordering to be reversed. If your player’s origin is at the top of the sprite’s head and the palette’s origin is at its bottom tip, then that means the player will be drawn behind the palette whenever the top of its head is above the bottom of the palette, which isn’t what you want. A good spot for the origins is likely to be the exact middle of wherever each object touches the ground.
Alright, tried your project. For the following three objects:
World
Goblin/Sprite2D
Pallet/PalletImage
You need to:
Set Y-Sort Enabled
Set Z-Index to the same value as your other objects
Remember that the container for your sort-able objects (World) and also anything drawn on the screen (Sprite2Ds) must be y-sortable with the same z-indexes.
If the threshhold for the overlap switch looks a bit off, try adjusting the position of your sprites’ origin within its parent object.
Also, you may find it easier to use z-index=0 (instead of 20) for all the ground-level objects/characters in your scene, so that you don’t need to keep setting it for every single node. The tileset can have a negative z-index to keep it underneath them all