I like to use a mix of 2d and 3d in my games. For sprites I want them to be pixel perfect. Otherwise there can be blurring or resize artifacts. One way to do this is to draw the 2d elements with an orthographic projection and the 3d elements with a perspective projection. But I don’t like this approach. Sometimes even when a sprite rests at a specific Z depth, I also sometimes want it to either fly in from behind the camera or rotate. And I want that rotation to have some perspective. Also what if you want 3d objects to interact with the 2d sprites? Or.. what if you want them to cast shadows on the 2d sprites.
The way I handled this in Big Bad Sudoku Book was to figure out what Z depth the sprite needed to be at to be pixel perfect. What that means to me is that every single pixel that I designed for the sprite in PhotoShop is represented by a single pixel on the device. There is always a Z depth for any perspective camera that will achieve this pixel for pixel representation of sprites. In all my games I find this Z depth and draw most of the game at this depth. For objects I set them to that depth.
In my own engine (written in Objective C/C/OpenGL ES 2) I calculated this 1:1 depth. I called it unityDepth. That depth is actually a distance away from the camera. Offsetting it from the camera’s Z gives me a focusZ. This simple offset only works if the camera’s facing is aligned with an axis, which mine is. By the way I was calling this unityDepth before I started using Unity3D. No sense in changing it now that I’m doing it IN unity. Anyway, when I started porting my next game to Unity3D I needed to figure a way to do this in their engine. Here’s a video I made that explains how to do it.
[x_video_embed type=”16:9″ no_container=”true”][/x_video_embed]