- Home /
Depth with Unity2D
Hello I'm making a Beat'em Up and i'm trying to do "depth" for example if an enemy is lower on the screen than you on the screen, he appers like if he was in front of you and when he go higher, he goes back you. I've tried to use Sorting layers but there is something who is every on the top layer. (Just in case, my player is animated in game) So what should I do ? Thanks
Edit : I made a video to explain : https://www.youtube.com/watch?v=vdSrmYqhpWg
Generally speaking, objects that are closer to the camera will always be rendered "on top" of objects that are further away. So to add "depth", don't fake it by adjusting the height (y), adjust the actual depth (z) relative to the camera.
Yes but if I use Sorting layer with a Sprite, no matter what depth (z) I use, it will be ever on the top
Surely if one wants depth (z coordinate), one would use Unity 3D as oppose to 2D?
If not, please specify, because if I am to help you, I need more information to get my head around a 2D-3D paradox.
Well look at this video of my game, you see that my player is on the top but Z axis change and it's doing nothing https://www.youtube.com/watch?v=X6QJm8NVisg
I now see what you mean. Thank you for specifying. I will try to write a script for you, but I'm being held behind schedule by a tree chopping issue, so please be patient.
Answer by alwayscodeangry · Jul 12, 2014 at 11:36 PM
Putting all your character SpriteRenderer
s in the same sorting layer and then setting their sortingOrder
based on their y position should have the desired effect.
Well no, i've already tried this but the player is composed of many Sprites so there is a special order
Answer by Corentin · Jul 13, 2014 at 09:37 PM
I did something similar (I can paste the script but there are some game-specific things inside), and just changed z position according to y position. if it's high on the screen (y), make it farther (z)
That's nit the solution, my player is made of many sprites which are sorted with Sorting Layer optuon in the Sprute Component and if I change Z axis it will do nothing
Your answer
![](https://koobas.hobune.stream/wayback/20220613153732im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI.depth factors 1 Answer
Using a Pre-Rendered Depth Mask? 3 Answers
From flat image to pseudo-3D, how to manage a texture/depth map couple ? 0 Answers
shader that includes texture, normal, and depth map 1 Answer
Shader - Writing to Depth issues 0 Answers