I want to change the height and the FOV of the camera based on the mobile resolution.

The issue is that 1- I am not excellent in math and 2- Some information is missing for me to find the missing pieces. I know one angle and one side, but I need more than that to know how to set the angle FOV and the correct height.

From the picture attached, I know the camera is perpendicular to the screen (so a 90 degree angle) and I can find one side of the triangle by getting the Screen.width/2.

What exactly is the relationship between the camera’s height and field of view? We need one to calculate the other, so unless there is a specific relationship it would be easier to define one and find the other relative to that, i.e.

//Let's say the height is at a constant 10
float height = 10f;
//Now that we know the side lengths of the right triangle, we can find the angles using trigonometry
float width = Screen.width * 0.5f;
float fov = Mathf.Atan (width / height) * Mathf.RadToDeg * 2f;
camera.fieldOfView = fov;

The basic idea is that;

//Where a is the angle we are trying to find
tan(a) = oppositeSide / adjacentSide
//In our case, the opposite side is 'width' and the adjacent side is 'height'
//If we want to find the angle 'a', we can use the inverse of the tan function - arctan (atan)
atan(tan(a)) = a
//But tan(a) = opp / adj as we saw earlier, so we can find the angle that way
atan (width / height)

Then to find the field of view, we convert from radians to degrees and double the angle. Now that we know the field of view, you can adjust the height with whatever ratio you want relative to the fov.

Hello @Namey5 and @mChapuis I am working on what appears to be a similar issue. I’ve used the math you laid out in this thread but am wondering what I’m missing.

I first specify the “height” which, if I understand correctly, is the distance between the camera and the player/map (not the height of the screen in pixels). This distance uses world units (aka uses values from translate.position) so perhaps this needs to be converted?

I attempted to use the formula you showed above but I’m getting FOVs which are either way too far zoomed out or way too far zoomed in.

To make sure I’m clear in my goal: No matter the device resolution I’d like to show the same amount of world map but zoom in or out depending on the device resolution.

Is it possible to fix the width and height of camera view so that the experience is the same across devices with different aspect ratios? Is a border/pillbox approach needed? Again, thank you very much for your time!!