Main camera field of view (FOV) angles in inspector doesn't match to actual used FOV of the main camera
I ‘am struggling with the calculation oft the FOV angles, because my results doesn’t match to the FOV the main camera actually used.
.
Why I ‘am doing this: I want to create a top down RTS game. To size my map correctly, I want exactly calculate, what part of the map will be visible in the main camera depending on the camera height, its position and of course on its FOV.
The problem: With the given vertical angle, I ‘am able to determine the top and the bottom border of my field of view (see picture 1). What is currently not working, is to determine the left and the right border of my field of view (see picture 2). I want to clarify, if I do something wrong in my math or if this is probably a Unity issue.
.
Step by step:
My settings:
Aspect ratio main camera: 16:9, 1920x1080 pixel
FOV vertical: 50°
FOV horizontal: 79,32° (by 16:9 aspect ratio, this one is correct)
Camera position x; y; z: 0; 25; 0
Camera pitch: 45° around the x-axis
.
Picture1
.
In picture one you see a side view of my scene (looking from the right side). The z-axis marked the ground of my map. P1 is the topmost point, which is visible in the game view. If you move it a little bit more to the right (+z) it will leaving the FOV to the top. The z-position of P1 (side b of the triangle) can be determined with simple trigonometry:
.
b = tan (70°) x a
.
a is the camera height which is set to 25, so b is 68,69. As you can see, when I set the z-position of P1 to 68,69 it perfectly matches to the top border of the FOV of the main camera. For the next step, we also need the length of the side c of picture 1, which can be determined with:
.
c = a / cos(70°)
.
Again with 25 of camera height, we will get 73,1. I have placed a 3D cube in scene with the scale 1f; 1f; 73,1f and it perfectly fits to the length of c. So everything seems to be correct. With this value, we go to picture number 2
.
Picture2
.
In picture two, we see the same scene with the same camera position and the same position of P1 but now we are standing in front of the scene. I now tried to get the x-position of P1 (side b in picture 2), so that it will perfectly fit to the right border of the FOV of the main camera.
I used again some simple trigonometry to achieve this:
.
b = a x tan(39,66°)
.
Now a in picture 2 matches the length of the side c from picture one. So the length of a is 73,1. With this value, we will get a length for b of 60,6. And if I move P1 to x = 60,6 it is outside of the FOV of the main camera. And this is not an issue of the gizmo which is drawn for the FOV of main camera, you won’t see an object at this point in the game view either.
Now from my point of view, and if all my calculations are correct, the main camera did NOT use a horizontal angle of 79,32 as mentioned in the settings, but a smaller one. Can anyone confirm my consumption or did I missed something?
Your answer
Follow this Question
Related Questions
Cinemachine preserve rotation and position on transition 0 Answers
Weird Rendering Unity5 1 Answer
Camer do not render correctly! 0 Answers
I cannot move my camera in the Game mode 0 Answers
Render only arms of the whole body 0 Answers