My game world is 3D.

The map is only 2D, however.

It is natural to think of the map as having an X and Y axis.

And it is natural to think of the world has having an X, Y and Z axis, where Y is upwards.

That is to say, X Y in 2D map coordinates is X Z in 3D coordinates.

What conventions and approaches do you have to keeping things straight at a code level to make mapping between them natural?

(Is Y usually upwards in 3D? Or do you have X and Z in map coordinates, or?)


2 Answers 2


Y up and Z up (where the respective axis is considered the upright direction in 3D) are just conventions. Modelling packages often have toggles to switch between them.

You should arrange your game around whatever makes sense to you. You can always accept incoming data in any coordinate system and convert it internally to match what the engine is doing.

If your game is truly 2D in nature, as in you plan to do all your game logic in 2D but just draw a 3D representation of the action, then you might want to consider working entirely with a 2D coordinate data structure until you come to your drawing code, where you promote it to 3D to pass to the graphics engine. You'll save memory, gain performance, and get to work in your familiar XY space.

If your game is just "conceptually" 2D, but you're actually still performing calculations in 3D for whatever reason (say you had an undulating terrain and projectiles that actually travel in 3D even though your actors cant), then I suggest deciding on a drawing coordinate system (very likely the popular Y up), and just getting used to writing your "2D" logic on the appropriate matching plane (the XZ, assuming the aforementioned Y up).

Maintaining a code base with two different overlapping 3D coordinate systems will get unbearably messy and annoying with no recourse, while just learning to think of the floor as XZ will snap into focus within hours.


Y is usually upwards in 3D, but the designations of the axes are rather arbitrary. To keep it simple I'd either have:

X (width), Y (depth), Z (height)
X (width) Z (depth) Y (height)

Keep the naming of the axes consistent between 2D and 3D. Conversion between 2D and 3D can be done with a simple function.

If you're interfacing a lot with a library that has a different convention then either use the convention the library is using or make conversion functions. The conversion functions could look something like this:

vector3D switchAxes(vector3D in)
  return vector3D(in.y, in.z, in.x);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .