Search Unity

2D - xy or xz?

Discussion in 'General Discussion' started by random1, Jun 26, 2013.

  1. random1

    random1

    Joined:
    Jun 19, 2013
    Posts:
    21
    Probably a stupidly obvious question, but how do you go about making a 2D game in Unity?
    By which I mean, do I rotate everything except the camera by 270 degrees around the X axis so that it is all X,Y.

    Or do I leave stuff unrotated, but rotate the camera itself, and have the game be X,Z?
    Using Orthogonal view.

    I'd expect 2D to be in XY, but having to rotate everything seems a rather clunky way of doing it. What am I missing?
    Thanks.
     
  2. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    I don't think it matters, but personally I think it'd make the most sense to adhere to the world axes based on your game. I wouldn't rotate anything, and point the camera towards the game being X, Z if it was a top down game, or X,Y if it's a sidescrolling game.
     
  3. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    I use Z as pointing at the player, and X is left/right from camera view and Y up/down. Just build your scene on one axis.
     
    Last edited: Jun 26, 2013
  4. random1

    random1

    Joined:
    Jun 19, 2013
    Posts:
    21
    Thanks both. I just wondered if I was missing a trick somewhere.
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    This. In Unity by default Y is generally expected to be "up", so I'd set my game up so that my logic matched with that. As in, I'd make +Y the direction that a character would jump in. This way things like Vector3.Up make make sense.
     
  6. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    +1;
     
  7. random1

    random1

    Joined:
    Jun 19, 2013
    Posts:
    21
    I wasn't clear unfortunately but I'm planning on a top-down rather than a side-on. Thus having "y" for "up" makes little sense - that should be z. Though of course Vector3.forward (z) would then actually go "up". Hence you can hopefully see my confusion. :)
    I'll just change the camera and use x,z I guess. Cheers.
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Why? You're basing a pretty fundamental design decision on the happenstance default orientation of the camera.

    Which way is "up" as far as your characters are concerned? If one of your characters was to be lifted off the ground, which direction would they move in? You should set up your scene such that that direction is +Y in the scene.

    If 'up' in your game should be 'towards the camera' then it makes sense to set up the scene (including the camera) based on that - so the game plays on X/Z, the camera is positioned somewhere in +Y and is pointed down -Y, such that it is in fact supporting the 'top down'ness of your game.

    But also, I have a feeling that when you say "up" you're thinking in screen space, where I'm thinking in scene space.
     
    Last edited: Jun 27, 2013
  9. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    Y is up regardless of what the dimension or position of the camera, 2D, 3D, don't matter, top down, side-scroller, don't matter. Y is always vertical. The position of where you build things in your level is what matters. It's the camera that changes between 2D, 3D etc, not the physics. Up means the direction the character's finger would be pointing if he was pointing upwards in respect to himself, not the screen.

    If it's a top down your camera used the x, z to move and y would be zooming in and out, if it's a side-scroller then the camera is using the x,y and z would be zooming in and out.
     
    Last edited: Jun 27, 2013
  10. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    It's a matter of personal perception. In truth, the player will never know the difference. What they see and experience will be the same no matter what theoretical plane it is moving along. In this scenario, what is most important is what you, the creator, perceives. If it seems logical to you, than it is correct. Everything after that is just a matter of consistently applying whichever orientation you go with.

    Personally, I prefer to keep things locked to the XY axis, and reserve the Z axis for depth from the camera. (and in orthographic cases, sorting) It makes it easier for me to compare screen space with game space. (since the final rendered screen is going to be 2D no matter what)
     
  11. random1

    random1

    Joined:
    Jun 19, 2013
    Posts:
    21
    Thanks for the clarifications
     
  12. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    I also (at least in my platform controller) make increasing X = moving to the right of screen = Vector3.right.

    This just makes a whole lot more sense in a 2d world, but it also means you need to look from the "back" view in the scene (because in 3D typically transform to the right means move to the objects right which moves it to the left of screen).
     
  13. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    This. Also keep in mind that by default all physics actions are axpecting to be Up in the positive Y-Axis. So if there's supposed to be any physics in your game then rotating your whole scene will very likely induce headaches very fast. I'd say: just keep it logical. :)
     
  14. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Depends on what you're going for.

    In my case, In my side-scrolling scenes, my camera has rotation (0, 0, 0) - by default this means it's looking at XY axes, with Z determining depth.

    My game is a bit of a one off since I'm mixing 3D and 2D - I use a perspective camera since that's something I make use of in my game. However, for a true 2D game, you would use an orthogonal camera.

    In short: whatever type of camera you're using, at least in Unity you shouldn't have to make any awkward rotations to make it work. If you're asking about Blender, on the other hand, I've found that the orientation of the object has to match the coordinate system, which makes things rather interesting. But, you're asking about 2D...so, I'll assume you're not.
     
  15. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190

    heh heh yeaaah
     
  16. e5an

    e5an

    Joined:
    Jul 6, 2012
    Posts:
    93
    For some reason this comic just popped into my head...
     
  17. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    In the context of Unity, Y is indeed "up". Seriously, go print the value of Vector3.up.

    Nobody's saying that this is some kind of universal mathematical truth. The point is entirely that you may as well work with your tools instead of against them, and in Unity and its APIs the convention is that +Y is up. Doing something else is certainly possible, but it will make life some degree more difficult.
     
  18. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    Ooooohhh. Lok I can even set it myself in modo:
    $oYZZZxp.png

    So what's your point here? In Unity Y is Up and you can't just compare that to any other 3D app.
     
  19. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  20. xtremepman

    xtremepman

    Joined:
    Jul 18, 2012
    Posts:
    388
    +1. 3ds Max's Feedback section looks just like Unity's. Did Unity copy them, or did they copy Unity? :-?
     
  21. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,971
    3ds max uses Z as up for some weird reason... but everyone knows the real up is Y!!
     
  22. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    If anybody ever asks you "what's up?" You better answer "Y!"
     
  23. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Added to the Great Index of Math Puns.
     
  24. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    A default camera, in an empty scene will be at -10, on the z axis. As Fishman said, x is left/right, Y is up/down, and +z points toward the player/objects. This seems to be easiest to mix 2D and your UI without having to do funky maths in your code everywhere. Also, for 2D, set your camera to Orthographic and set the ortho size to 1/2 the height (so 384 for a 1024x768 game) - which means 1 unit of pixel dimension equals 1 unit of x/y making it easier to keep your UI 2D objects in sync.

    Gigi.
     
  25. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Lol.
     
  26. sushitommy2

    sushitommy2

    Joined:
    Apr 3, 2013
    Posts:
    4
    Building on the XZ plane might be a better idea if you plan to use Unity's NavMesh for pathfinding. The NavMesh generator always uses the XZ plane.
     
    AlMekan likes this.
  27. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    Anyway, they should really find a standard between they all (and leave the option to choose the legacy mode), not only the coordinate system but the measurement system too (thank David Unity looks a lot like Maya).
     
  28. create3dgames

    create3dgames

    Joined:
    Aug 20, 2012
    Posts:
    275
    Positive X is forward in a 2D game, negative X is backward, positive Y is up, negative Y is down, and Z is irrelevant. Z should always be set to zero in a 2D game. Once Unity 4.3 comes out we won't have to worry about any of that any more though.
     
  29. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,440
    I've never had a problem with the Y Up or Z Up distinctions, as it's really quite arbitrary. Euler angle ordering is also arbitrary and you can get pretty confused if you don't match systems.

    But I really wish all products used a right-hand coordinate space. Microsoft really made a stink when they chose left-handed coordinates for DirectX, all these years ago, even after SGI GL and most other CAD used the textbook math-and-physics-tradition for years. It was done as a sort of lock-in move, and here we are years later having to work around such distinctions between products.
     
  30. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I thought it was funny that Unity added a Quad primitive in 4.2, apparently to support 2D somewhat, but they rather bizarrely generate it on the X-Z plane which is NOT the most common plane for 2D games and makes no sense unless you're doing a top-down thing.