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?)
Answer
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.
No comments:
Post a Comment