1
\$\begingroup\$

I wonder if anyone can help with an explanation of the z-axis and using unity with 2D with an orthographic camera.

Up until now i have only been modifying the x and y values of game objects, thinking this is the correct way. i thought the Z axis didn't exist in 2D space (i.e. unity 2d with orthographic camera) but I do notice that the orthographic camera is placed at -10 on the z axis, if i change this value then the camera disappears. I sort of began to accept that.

Now I cam to a point where I wanted to rotate something, and I notice that rotating eithe on the z or x axis, doesn't seem to do anything, only on the z-axis, there is that z-axis again !

Can anyone tell me when i should be worrying about the z axis in unity using 2D games.

It seems now that it is more important than I once thought :-)

Thanks in advance.

\$\endgroup\$
1
  • \$\begingroup\$ Note that Unity is natively a 3D game engine, with a 2D mode on top. Click the "2D" button in your scene window to toggle off the 2D scene camera, which will let you see that your game has a 3rd dimension at all times. Orbiting around in this 3D view can give you a better feel for what's happening on each axis. \$\endgroup\$
    – DMGregory
    Jul 1 '17 at 16:50
3
\$\begingroup\$

Here are some important points about Z axis in 2D mode:

  • An object needs to be in a camera's view frustum in order for the camera to render it. So, if your object is at -10 Z position and your camera is at 0 Z position, your camera can't render the object properly.

  • For 3D objects, Z position determines the visual draw order. Let's say you have 2 3D objects: A and B. If A has a Z value greater than B, that means B will be drawn in front of A.

  • For sprites, however, this is not the case. The draw order of sprites is determined by two settings named "Sorting Layer" and "Order in Layer" which can be found under the Sprite Renderer component. The Z position has no effect in visual draw order of sprites.

  • 2D physics' collision-resolving ignores the Z coordinate. See the gif:

2D physics Z coordinate indifference

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the reply, I am beginning to understand it now although with regards to the rotation, I am still a little confused. THe rotation only seems to work on the Z axis in 2d. Is this correct? I tried siwtching to 2d mode but couldn't understand why z was only affeced. I supposed its just one of those things you have to accept ? Rotation for clockwise and anticlockwise only happens on the z axis ? \$\endgroup\$
    – Martin
    Jul 2 '17 at 7:58
  • \$\begingroup\$ @Martin Rotating around Z axis means rotation on XY plane. Rotating around Y axis means rotation on XZ plane. Rotating around X axis means rotation on YZ plane. Since Unity's 2D mode uses XY plane as the 2D plane, the expected behavior of 2D rotation must happen around the Z axis. This doesn't mean you can't rotate around other axes, you can, but it won't make much sense in general conditions. I will try to explain this more with a diagram when I have some free time. \$\endgroup\$ Jul 2 '17 at 11:19
  • \$\begingroup\$ Hi, thanks for the info. With regards to the diagram, that would be great and really helpful. Thanks \$\endgroup\$
    – Martin
    Jul 4 '17 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.