Adjust the height of the camera according to z-value

Hi Guys,

I am struggling at this for over 2 days… plz help me…

I have to zoom in and out in my game… so, I am just moving position.z of the camera…

so, as shown in the figures, the red line appears a little higher after I decrease camera.position.z

[7840-fig+2.png|7840]

But, I want the red line to stay at the same position as before i.e., at the same height from the bottom as before. So, how should I increase the height of the camera ?

I do not know the distance between the red line and the bottom.

I am so confused here. Please help me.

I also know that I can increase and decrease fov instead of the z value. but, I am more confused there. In any way, how do I adjust my height ?

Hey guys,

I solved it…

if it helps here is the solution…

translate the camera height to (dz)Mathf.Tan(Camera.mainCamera.fieldOfView0.01745f/2);

dz is the delta z you moved the camera. and that 0.1745f is to convert that to radians.