Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Is there a way to remap the coordinate system?

Discussion in 'Editor & General Support' started by Weckar, Apr 12, 2021.

  1. Weckar

    Weckar

    Joined:
    Sep 9, 2019
    Posts:
    3
    As of right now, I am building a grid-based tactics game. I want my code to be as much as possible unaware of the graphics, to the point where I could switch out 2D for 3D of vise-versa if I so chose.

    However, Unity's 2D and 3D coordinate system to not naturally line up for my game's type of perspective. In 2D, y is north-south while in 3D z becomes north-south. This means that while working in 2D, to refer to north I need to use Vector2 (or Vector3).up, while in 3D I need Vector3.forward. You can see how this gets messy fast.

    Is there a way in unity, native or with an asset, to remap what axis VectorX.up/VectorX.forward and their cousins relate to? Or, indeed, to make 2D mode use the XZ grid rather than the XY grid? Either would solve my issue.

    As a sidenote, one might say: Why not just build your 3D game on the 'wall' and always use XY? Mostly because the scene camera in 3D mode will always consider Y to be up, making it extremely awkward to get angles when editing maps.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    This is extremely smart. The easiest way is to store your unit positions in your own data structures on a MonoBehavior, then each frame you would translate that position out to the underlying Transform for that unit.

    Alternatively you can keep everything about this in your own separate non-MonoBehavior objects, with linkages to the GameObjects involved, and then your code would even work without Unity. But that requires a LOT of extra plumbing to go back and forth.

    Either way, as long as your game process logic only operates against YOUR data structures, you can make the final render-to-Unity be whatever you like.
     
    Joe-Censored likes this.
  3. Weckar

    Weckar

    Joined:
    Sep 9, 2019
    Posts:
    3
    While that is an option, I'd prefer to not abandon the utility of in-scene editing altogether.
    Personally, I don't see why using a different plane in 2D would be so difficult for the engine to handle?
     
  4. Weckar

    Weckar

    Joined:
    Sep 9, 2019
    Posts:
    3
    Not resolved, by the way... Still looking for an extension or something that is scene view compatible,
     
  5. slider115

    slider115

    Joined:
    Sep 23, 2019
    Posts:
    5
    This probably isn't what you are looking for, but I am working on an application that is a 3D virtual reproduction of a construction project. As such, the coordinate system used in the 'real world' is X is East(+ve)-West(-ve), Y is North(+ve)-South(-ve) and Z is Up(+ve)-Down(-ve)/Elevation. I do all my regular math and angles in the 'real world' coordinates and convert them to unity coordinates before using them with a game object. Here is the function we use:


    Code (CSharp):
    1.  
    2.     public static Vector3 ConvertToVector3(Point_3D Point)
    3.     {
    4.         Vector3 result = new Vector3(0f, 0f, 0f);
    5.  
    6.         result.y = Point.z;
    7.         result.x = -Point.x;
    8.         result.z = -Point.y;
    9.  
    10.         return result;
    11.     }
    12.  
     
  6. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,052
    why use gameworld positions?

    use positions relative to a main top parent. then once you switch to 3D you will have the 2D sit on the x y axis (like the UI canvas)

    then you rotate the main parent 90° and you are good to go.