Sprite y-sort issue

Godot Version

4.2.2 stable

Question

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.
pallet
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.
pallet-99
I’m trying to get to walk behind the crates and infront of them.
behind_crate
infront_crate

I have the player set to z-index of 20
The static body and animated sprite are z-index of 10
Any suggestions?
Thanks

Lower z index means it will ALWAYS be drawn below higher-z-indexed sprites. If you want to use y-sort, they need to have same z-index

so i would set the player and the object to the same z-index? that didnt seem to work

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.

I must still be doing something wrong somewhere.

I set the player to z-index 20,with y-sort on. I set the pallet to z-index, with y-sort on, and it still doesn’t work right.

Can you (or someone) take a look at the project and verify that I have it set up correctly?

http://www.webpage-builders.com/Test3.zip

Where do i change this?

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.

Awseome!

I see now, it was setting all the items with a z-order and a y-sort on.

Thank you so much!

1 Like

No problem!

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

ah, yes, i can see that would be helpful

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.