I'm attempting to create 90 degrees top-down scenes where I'm working with a 4k or larger camera. What I'm trying to do is drop a script on the main camera and have a debug line that updates the main camera in [Execute Always] mode to tell me how many world units are visible to the camera width and height. For example, when dealing with a 1920x1080 camera I need to ensure 53.1876 width and 29.8704 units height are visible. When I switch the main camera to 5760x3420 I want to be able to ensure there are exactly 159.5628 units width and 89.6112 units height visible. The debug will allow me to change the camera's x value to increase or decrease altitude from game terrain or surface objects to achieve the desired number of visible world units width and height. I have tried to use ScreenToWorldPoint and ViewPortToWorldPoint but haven't been able to achieve desired results.
I was able to produce the desired effect with an Orthographic camera easily since the relationship of the orthographic size exactly corresponds to how many world units will be width and height when the aspect ratio is known such as the code example.
var height = 2*Camera.main.orthographicSize; var width = height*Camera.main.aspect;
So I knew if I wanted a heights of 29.8704 I just had to make the orthographic size 14.9352. I'm looking to replicate this with a perspective camera while understanding the differences in views.