Search Unity

Question Looking for advice on how to handle -Z being "up" in 2D

Discussion in '2D' started by jtsmith1287, May 14, 2023.

  1. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    I'm tinkering with a Dwarf Fortress clone. I generate a map using multiple layers of Tilemaps. The Z axis is my up/down as I use X and Y normally for 2D.

    I imported some character art the other day and realized it was reversed, and it dawned on me I generated all my terrain with higher elevations being along the +Z. But this means +X is actually left, and all my art is inverted. I felt like that would be confusing, so I flipped my initial height calculation negative and inverted the map. So now, if I want to go up in elevation, I go negative on the Z. Ew

    This is breaking my brain and it's getting really tedious to code around. So my question is, how big of a deal will it be, or rather, what things might I not be considering if I wanted to go back to +Z being "up"? I feel like flipping my art 180 degrees and just remembering that Left is Right and Right is Left will be MUCH less painful than trying to do all my pathfinding and elevation calculations inverted.

    Thoughts? How do other people handle this?

    Extra context, but likely not necessary to contribute with an answer: I track my layers in 2 ways. I track the total number within an array. So, if I have 32 layers and I want the top layer, I get Layers[31]. I also track my layers relatively to where the "middle" is, which use for water levels and whatnot. So 0 is the water level, and the highest layer is 15 and the lowest layer is -16. Well, no, right now the highest layer is -15 and the lowest layer is positive 16. An issue I'm facing right now, is I want to place a character on the map. It's procedurally generated so I pick the highest layer, and then get layers until the surface material != "Air" to avoid placing a character in the sky. But with this negative height thing and relative layers it's all kinds of buggy and my brain is breaking. I didn't think it would be difficult. "just use normal logic, then flip it negative". But no, somehow it's not that, and I only get 90% of the code paths returning expected values.
     
  2. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    i also use Z as elevation and negative means higher

    I just got used to it after a while

    How it was useful for me to remember:

    Z = 0 is top of the map, cant go higher as you increase z you go down, the logic is the same with the multi dimensional arrays
     
    Last edited: May 14, 2023