- Home /
How to scale a plane & fit it screen..?
Get the screensize (width & height), and i want to fit my plane on screen.
Answer by Serotonindude · Aug 28, 2015 at 12:07 PM
ATTENTION:
If you try the correct, simplified formulas
var height = 2.0 * Mathf.Tan(0.5 * Camera.main.fieldOfView * Mathf.Deg2Rad) * distance;
var width = height * Camera.main.aspect;
with Unity planes consider, that a plane in Unity with the scale 1 is actually 10 units in size (wtf?!), in contrast to every other basic primitive (cube, sphere, etc...).
It took me 6 hours to find out, why i had to divide the height by 10 to match the screen.
Hey, for this example, what's the distance variable? Thanks
hi, the distance of the plane from the camera's origin (along the forward vector)
Answer by robertbu · Jul 12, 2013 at 02:12 PM
At any given distance from the camera, you can calculate the size of a plane to fill the camera by:
var height = 2.0 * Mathf.Tan(0.5 * Camera.main.fieldOfView * Mathf.Deg2Rad) * distance;
var width = height * Screen.width / Screen.height;
But if you are just trying to resize a plane for different resolutions, size the plane in the editor so that the height fits then do the second line of the calculation above to get the width in a script.
Answer by RobDaPraia · Aug 17, 2014 at 02:20 PM
Thanks a lot, small typo:
var height = 2.0 * Mathf.Tan(0.5 * Camera.main.fieldOfView * Mathf.Deg2Rad) * distance;
var width = height * Screen.height / Screen.width;
Should be:
var height = 2.0 * Mathf.Tan(0.5 * Camera.main.fieldOfView * Mathf.Deg2Rad) * distance;
var width = height * Screen.width / Screen.height;