This isn't for an animation, so I'm not inserting keyframes - as I view the model through the virtual camera, I want to experiment with different focal length values in Eevee and Cycles; but to not lose the model, I want to move along the Y-axis specifically to keep the model roughly the same size in the frame.
This solution uses only 1 driver, to drive the y value of the camera's transform depending on its focal length.
I used a linear regression calculator online (Search "Linear regression calculator" on your favorite search engine) and I mapped a few values of the focal length and the resulting y value necessary to keep more or less the same objects in frame. I arrived at a value of y (transform) = 0.28 * focal length +1. I assume the exact values will be different from scene to scene but it can be found quite easily using said regression calculator. I used this simple setup :
In order to drive the y transform value, right click in the focal length field and choose "Copy as new driver". Right click in the y transform field of the camera and choose "Paste driver". Right click again in the field, and choose "Edit driver". Then change the evaluation type to "scripted expression" and enter the above formula (in my case 0.28 * lens + 1) :
The result :
If you want to use this technique to be always true for its local z-axis, that is to say the forward/backward axis of the camera, follow this :
- Select the camera, Press SHIFT + S then choose "Cursor to Selected"
- Press SHIFT + A then choose "Empty" (whichever type)
- Add a "track to" constraint to the empty, set it to one of the objects of focus in your scene. If you don't have a particular object, just add a new empty and set it somewhere in the middle of your scene. The constraint should look like this :
- Select the camera object, then the empty, and press CTRL + P, choose "Set parent and keep transform" Now when you move the empty around your scene, the camera should follow it exactly and always turn toward the focus object you chose earlier. Do not move the camera directly . If you followed previous steps this should already be working. You will most certainly have to tweak the values a little bit though.