- Home /
Unity 2DToolKit sprite sort problem
I use Unity with 2DToolKit to develop a 2d game. Now I have two sprites(A and B) in the scene and they have the same Z value. How can I put A on the front of B or put B on the front of A ?
Answer by Fattie · May 22, 2013 at 08:26 AM
For beginners:
Simply move the game object forwards or backwards ... that is to say nearer or closer the camera. Click on the game object (the sprite) in your editor. notice the red, green, blue arrows. Grab one of the arrows to move the object. For beginner articles, try unityGEMS.com, it's great !
For badass 2.5D developers:
This is a core concept in 2.5D games: you have all the colliders on one layer .. say z=10, for example. You actually have the sprites separate, on their different layers .. perhaps 15 and 16 in the example.
However, there is a simple, clever trick to get you by in many situations:
http://answers.unity3d.com/questions/307540/is-it-possible-to-cast-a-ray-but-ignore-z-position.html
Step one, your two sprites put them on slightly different layers .. say 5 and 6 for example.
BUT in fact make the colliders REALLY DEEP ... say 5 deep.
then it will still work perfectly.
To make it clearer for you when working in the editor, simply change the position by a small amount (perhaps 0.05) but make sure the colliders are, say, 2 deep.
Recall that -- of course -- you will have the various rigidbody locked-off so they can only rotate on Z, or depending on your game, likely not rotate at all, and not move back and fore on Z.
Pls vote up that answer ...
http://answers.unity3d.com/questions/307540/is-it-possible-to-cast-a-ray-but-ignore-z-position.html
if it is useful to you, as it is a critical trick in 2.5D games!
Two sprites need collision detection, so two sprites must have the same Z value. How can I sort the sequence without changing the Z value ?
Your answer
![](https://koobas.hobune.stream/wayback/20220613102718im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotating a sprite distorts it? 0 Answers
SpriteRenderer change order in layer in edit mod via script 1 Answer
Custom 2D armor slots 1 Answer
make rain with sprite sheet in unity2d 2 Answers