- Home /
Camera zoom for Free Look Camera Rig
I would like to add mouse zoom capability to Free Look Camera Rig and Third Person Controller from Standard Asset, but I am unable to understand how they set up the camera distance from character. The best I can do is to move the Pivot but with erratic results.
Anyone know what variable is responsible for camera distance from character and/or how to do zoom?
Answer by smacbride · May 04, 2015 at 08:52 PM
I use the scroll wheel and change the camera's field of view. Works great.
Use the Mathf.MoveTowards function listed here: http://docs.unity3d.com/ScriptReference/Mathf.MoveTowards.html
could you provide more details? At least, how to you assign camera's position Z value?
Answer by kalishuck · Nov 03, 2016 at 09:13 PM
Have the same problem. What I found, is that you can use Camera's fieldOfView property for zooming. See http://answers.unity3d.com/questions/218347/how-do-i-make-the-camera-zoom-in-and-out-with-the.html
So, for Free Look Camera Rig, the script will look something like this:
var scroll = CrossPlatformInputManager.GetAxis("Mouse ScrollWheel");
if (scroll != 0) {
var cam = m_Cam.gameObject.GetComponent<Camera>();
var fov = cam.fieldOfView;
fov += scroll * 10f; // 10f - intensivity
cam.fieldOfView = Mathf.Clamp(fov, 25f, 100f); // 25f, 100f - min, max borders
}
There are also some comments saying that manipulations with FOV could cause nausea and distortions... but who knows...