- Home /
Formula for the scale value of an object based on ortographic camera size?
Hello,
I'm having some problems scaling objects to their expected size. I'm using an ortographic camera of size 540(half of 1080, wich is the base height I'm working with). I have an object with an sprite that has a size of 32x32 pixels. And there's the problem. It seems a lot smaller than what it should, and I do not know wich value I should scale so that it looks "correct".
Is there a formula that could be used to calculate the object scale value so that it looks like 32x32(the "correct", expected size)in the world?
Thanks in advance!
Answer by pako · Apr 05, 2018 at 08:25 PM
There is no "correct", expected size really. I mean, the "expected" is subjective, so, I assume that by "expected" you mean "desirable" size.
I have no formula, but I'll explain by example. Here's how I go about it:
If a sprite is 32 pixels high, in a screen 540 pixels high, it will occupy (32/540)x100 percent of the screen height. This equals to 5.9% (0.059 x100) of the screen height. In a mobile phone whose display has a height of, for example, 6 cm, the sprite will appear as 5.9% of 6 cm in height, which is 0.059x6 = 0.35 cm (3.5 mm), since the 6 cm correspond to 540 pixels in height.
In another mobile phone which also has a display of height 6 cm, but its resolution is 1080 pixels in height, the 32 pixels will represent 0.03 (32/1080 rounded) of the screen height, so the sprite will appear as 0.03x6 = 0.18 cm (1.8 mm - there's some rounding error here, but that's beyond the point).
So, what is the "desirable" size?
Well, you'd better start from the end of the above calculation, and work towards the beginning:
You have a mobile phone of 6 cm display and 540 pixels resolution in height. Your desirable height on screen for your sprite is 7 mm, i.e. 0.7 cm. So, you want your sprite to cover 0.7/6 = 0.117 of the height of your phone. Since your phone is 540 pixels in height, you need your sprite to be 0.117x540 = 63 pixels.
Therefore, you need your sprite to be 63 pixels in height, which is close enough to 64 pixels, and since your original sprite is 32 pixels, you could either apply a x2 scaling, which will make it look very pixelated, or create a 64 pixel in height sprite directly.
With your 32x32 square sprite you work with height, because it's convenient for you to do so, but you could also do a similar calculation with width, if it was convenient for you to set the desirable screen size for your sprite in in width. And if your sprite is rectangular, and you want to create a sprite from scratch, you could do the above calculation for both height and width.
Of course, this can be applied to any screen resolution and aspect ratio.
Now I get it. Unity is indeed a very well made engine. Thanks a lot!
Your answer
Follow this Question
Related Questions
With a perspective camera: Distance independent size gameobject 5 Answers
Newbiew question: how to size objects? 1 Answer
SmoothDamp bounce effect 0 Answers
Change camera ortographic size to fit the content 1 Answer
Unity camera size issue 1 Answer