bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.65k stars 3.52k forks source link

Parent scale.z affects child sprite z-index #4149

Open SecretPocketCat opened 2 years ago

SecretPocketCat commented 2 years ago

Bevy version

0.6.1

Operating system & version

Win 11

What you did

Spawned a parented sprite and change the parent's scale.z to something other than 1.0

What you expected to happen

Z-index of a sprite wouldn't be affected at all or the transform of the sprite would affect it as well.

What actually happened

It's affected by the parent transforms

Additional information

Repro https://github.com/SecretPocketCat/bevy_issue_repro/blob/sprite_index_scale/src/main.rs (the expected order from bottom would be red, green, blue) 2022-03-08 11_18_46-bevy

lukors commented 2 years ago

Isn't this behavior expected considering the sprite exists in 3d?

Isn't what you're referring to as "z index" actually just the Z position in 3d?

Or am I misunderstanding something?

SecretPocketCat commented 2 years ago

@lukors My issue is that only the parent.z scale affects the final z position, but not the transform of the sprite itself.

alice-i-cecile commented 2 years ago

My opinion here is that this is a clear and compelling argument in favor of dedicated Transform2D types. This behavior is very surprising to beginners, and just adds to the friction of trying to make 2D games using 3D transforms.

SecretPocketCat commented 2 years ago

That would be great.

pmikolajek commented 1 year ago

As a newcomer who just stumbled on this and spent some time figuring it out, here's how I would have expected this to work for 2D:

This would also be consistent with the docs in transform.rs, which mention z-ordering for translation but not for scale. As it is, it really is not clear at all how translation, scale, and child entities interact when it comes to z-index calculation. (Incidentally, is there a write-up about that somewhere, without looking through the source?)

I don't know how that would play with the larger implementation or 3D handling. It's just what would fit my initial, intuitive model.