I can't fit a plane to my field of view
I'm trying to fill the screen with a plane which will be my play Area for an Android game. The thing is that this code:
playArea.transform.position = new Vector3(0f, 0f, 5f);
var frustumHeight = 2.0f * Mathf.Tan(Camera.main.fieldOfView * 0.5f * Mathf.Deg2Rad) * playArea.transform.position.z;
var frustumWidth = frustumHeight * Camera.main.aspect;
playArea.transform.localScale = new Vector3(frustumWidth, 1.0f, frustumHeight);
doesn't seem to work. I get 3.849002 for height and for width 5.773502, when I would need 1.535 for height and 2.31 for width (approximately).
Thanks for any insights!
Is there a reason you're using perspective ins$$anonymous$$d of orthographic? "play Area for Android game" gives me the impression that perspective view may not be what you want.
Answer by snertingen · Jan 02, 2018 at 09:03 PM
@serious6 I'm using following code to find my screen size (frustum). Don't know if it help you, but just in case:
var cam = Camera.main;
var planes = GeometryUtility.CalculateFrustumPlanes(cam);
var distance = planes[4].distance; //Ordering: [0] = Left, [1] = Right, [2] = Down, [3] = Up, [4] = Near, [5] = Far https://docs.unity3d.com/ScriptReference/GeometryUtility.CalculateFrustumPlanes.html
var frustumHeight = 2.0f * distance * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad);
var frustumWidth = frustumHeight * cam.aspect;
Your answer
Follow this Question
Related Questions
camera to mouse position problem 0 Answers
Changing Camera Field of View 0 Answers
Simulation of vision impairments like Glaucoma and Cataract 0 Answers
Dynamically adjust any plane infront of Camera 0 Answers
Camera Field of View 2 Answers