- Home /
2D Camera Question: Pixel Perfect W/O Cutting Bottom Edges
Hey there Unity Community.
This is my first thread here and my first project in the Unity engine.
I am designing a 2D endless runner at the moment and I have run into some difficulties in terms of camera scaling. At the beginning, I simply slapped on a script that took the screen height / 100 / 2 and used that as the camera scale. This created pixel perfect image quality.
However, I have now realized that this script alone is simply not going to do the trick.
Whilst it does make the game look sharp at any aspect ratio, etc, I need to figure out a way to maintain this crisp quality whilst preventing the vertical axis from scaling to the point that you can now see under the floor of the platform.
This means that I need to either:
a) Modify the script so that the game will scale the same but the vertical axis will never start below my platform.
or
b) Modify the script so that the game will be pixel perfect (or at least close to it) but only scale the horizontal axis (the horizontal axis doesn't effect gameplay substantially for my game style).
Here is the script I am currently using:
// set the camera to the correct orthographic size
// (so scene pixels are 1:1)
s_baseOrthographicSize = Screen.height / 100.0f / 2.0f;
Camera.main.orthographicSize = s_baseO
How can this be modified to do either of the above?
Thanks so much for your help!
Answer by Kensharma · Mar 05, 2014 at 04:58 AM
To elaborate on method 1 if I didn't explain this well enough;
Method 1 essentially means that the camera will adjust itself so that the bottom of the screen is always at a certain point (so that you always see the bottom being the egde of the platforms) and add the ortho size from there.
E.X. My platform starts at y -1 and ends at y 2 (height). The camera needs to start at -1 (height) and then add the screen height / 100 / 2 to keep it pixel perfect.
If you have any other methods I could use (I heard about scaling by multiplying size of objects, would love to know how that works) feel free to suggest those aswell.