0
\$\begingroup\$

enter image description here

So i'm making a 2D top down game setup in 3D using tilted Sprites and angled orthographic camera.

My camera setup is as shown.

In my game I have the floor flat on the X/Z plane with walls/characters rotated +45 degrees about the X axis. The orthographic camera is pointing down also at 45 degrees about the x axis, parallel with my walls/characters.

As a result, I dont see any distortion for players/characters since they face the camera directly on, while the ground however sees a distortion of sqrt(2) shorter. This makes sense considering how an orthographic camera works. To fix this, I've made my Tilemap set up with X:1 Y:1 Z:Sqrt(2) so that each tile is stretched on the Z axis by Sqrt(2) to compensate for this distortion.

All looks well with only one problem now... foreshortening with regards to movement: Forward and backwards movements of objects/characters along the z axis are perceived to be slower than movements left/right on the x axis. This makes sense because while each tile is perceived to be a square in the camera view thanks to scaling Z on the tilemap by sqrt(2), the real world tile is, well, sqrt(2) times taller than its width, so obviously it takes longer to travel forwards / backwards.

How do i correct this?

\$\endgroup\$
0
\$\begingroup\$

If the tile is sqrt(2) times taller than wide, then multiply z-axis motion by sqrt(2)

\$\endgroup\$
0
\$\begingroup\$

Myself, I'd recommend getting rid of the stretching and leaning in your game world.

Make the tilemap uniformly scaled 1x, and make any upright characters/walls/trees stand perpendicular, not leaned over.

That way both the z and y axis are equally foreshortened in your camera's view by a factor of \$\frac 1 {\sqrt{2}}\$.

Then, modify your camera's projection matrix to add a vertical scale factor of \$\sqrt{2}\$ to compensate. This applies the stretching in the render step alone, so it does not interfere with your gameplay/movement logic or force you to do fiddly things like leaning sprites diagonally.

In Unity it would look something like this:

Matrix4x4 mat  = camera.projectionMatrix;
mat[1, 1] = Mathf.sqrt(2) / camera.orthographicSize;
camera.projectionMatrix = mat;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.