Some Context:
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.
My initial approach to fix this was to set up my Tilemap with a scaling of 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.
However, my one problem now is that I experience 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 in the game view. 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 longer along the z than its x/width, so obviously it takes longer to travel forwards / backwards than it does left/right.
Honestly, I would also love to hear from others on how they have approached this issue (especially with a game like Enter the Gungeon), but from what I have learned in the past few weeks is that there are three approaches:
- Move everything locally / using local transformations (underneath a root scene object that is made sqrt(2) times longer, which in this case would be my tilemap).
- Adjust all movements of objects in the z-axis to be faster by a factor of sqrt(2).
- Use an oblique projection: unity - How to handle forward/backward movement in an oblique top-down view - Game Development Stack Exchange
I’m very hesitant regarding Approaches (1) and (2) as not only do I use rigidbody forces everywhere, but I’d also be concerned about fixing all my other systems (for instance usages of overlap spheres) to make sure they see an appropriate scaling as well.
So now I’m left with option (3), which is the least I know anything about (specifically regarding projection matrices and oblique projections).
My Question(s):
- Is there a way to set oblique projections in Cinemachine?
- How do I calculate the appropriate matrix given the environments I have set up? I.e. a camera pointing 45 degrees downwards at the floor.
My attempts so far have been to use this package here:
https://github.com/keijiro/unity-oblique-projection
The package/component has three params to play with. Setting the Angle parameter to 0 (seems to rotate camera around the y axis, which I dont need), eyeballing the Z-Scale parameter, and arbitrarily moving the Z-Offset parameter so that the camera is centered where it was before, I can see the results I want: neither walls/character nor the floor see ANY distortion, and I dont have to scale anything at all.
BUT, I want to figure out how to set the Z Scale and Z Offset precisely (based on calculations), and not just eyeballing it. Given an orthographic size and camera angle, how do I calculate what these parameters should be?
Any help is greatly appreciated Thank you if you read the whole post!