- Home /
Rendering order of objects in different depths not correct.
Hello, I'm having problems with rendering objects in the correct order according to depth. Right now I have a script that will instantiate "Card" objects, which are simple Quad meshes with a texture. The script calculates their position and Z-axis rotation to arrange them in a "card hand" pattern.
What's giving me problems is having the cards render in the correct order, in which the right-most card is at the back, and the left-most card is at the front. I tried to do this by making each card be 1 unity apart on the Z axis. However, this gives me the following result:
Only when I distance the cards by steps of 20 units in depth do I get the desired effect:
I was wondering why is it that separating the cards on steps of 1 unit in depth doesn't create the same effect on rendering order. The problem with separating them by 20 units is that the sizes of the two edge cards are too different. It also creates this "spiral" type of pattern, rather than a clean circular pattern. Is there any other solution for this?
Thanks!
I'm actually using a perspective camera, since the other objects on the scene are all 3D. It's only the cards which are 2D.
Answer by Hans D. · Sep 24, 2013 at 05:32 PM
Thanks for the input guys. After searching a little bit more I found my problem in this thread.
I'm using a perspective camera since other objects in the scene are all 3D, the only 2D objects are the cards. As recommended in that thread, what I did to solve it is set
Camera.main.transparencySortMode = TransparencySortMode.Orthographic;
And set my card textures as transparent. That made them sort correctly by depth, producing the desired result. Thanks!