- Home /
Grouping sprites 2d order
I have two gameobjects with some sprites that depicts two characters.
The problem is, when one pass through other they blend, ie, the head of one stays in front of the body of the other. The hand of one stays in front of the body of the other. THe expected result is the whole body (all sprites) stays in font or in back of the other character. I dont know how to achieve that.
Answer by TrevorP · Mar 11, 2014 at 02:42 PM
When you instantiate your player objects you'll need to set their transform.position.z values. If they both have the same z values for the sprites and are on the same sorting layer they will get mixed up like you describe.
I had a similar issue where I had a Player object with head, body, and legs sprites as children of the Player object. When two players ran into each other they would melt together. Changing the Player object's z value (and by relativity, the child sprites) it fixed the issue
the problem is "Order in Layer" property... even if i change z, using Order override it.
So it seems I will have to set them all to zero and control z-order only by z transform :(
Oh, yeah. I should have mentioned my players are on the same sorting layer and the Order in Layer is zero'd out for everything. I'm not sure what the best way to order cloned objects / objects with the same ordering.
One option is to increment the Order when you instantiate a player object
Answer by BrunoMikoski · Mar 11, 2014 at 03:08 PM
Do you are using Unity 3D?
If the answer is yes you need to use the layer orders: https://www.youtube.com/watch?v=K-vin66NsiQ
If you are using just sprites, you need to organize that using the Z index.
Answer by ImpishMario · Mar 11, 2014 at 03:07 PM
Assuming that you make 2D game, it's enough to set proper sorting layer order for your game objects containing Sprite Renderers ("z" position is irrelevant in 2D in terms of sprite rendering). Try this: for character A, set sorting layer in each Sprite Renderer component (child and parent) to 10 and for character B, set them for e.g. 20. Whole character B should be visible "in front" of character A then.
Hope this helps.
This isn't entirely true. The Z position becomes relevant if the sprites are on the same sorting layer.
This doesn't work if the sorting layer is not defined, which makes it unusable for a dynamic approach.
Your answer
Follow this Question
Related Questions
2D sprite rotation with velocity and interpolation 1 Answer
Sprite disappears in front of background 1 Answer
Scissor tool with 2d sprite 0 Answers
SpriteManager 2 1 Answer
How to alternate images in 2d unity 0 Answers