- Home /
Help me with smooth zoom
Anyone can make the zoom smooth for me please, i really need it, thanks all. using UnityEngine; using System.Collections;
public class abc : MonoBehaviour {
public float zoomSpeed= 250;
public float zoomMin= 5;
public float zoomMax= 80;
void Start()
{
}
void LateUpdate()
{
float scrollwheel = Input.GetAxis("Mouse ScrollWheel");
if (scrollwheel > 0)
{
camera.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed * 0.01f;
camera.fieldOfView = Mathf.Clamp(camera.fieldOfView, zoomMin, zoomMax);
}
if (scrollwheel < 0)
{
camera.fieldOfView -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed * 0.01f;
camera.fieldOfView = Mathf.Clamp(camera.fieldOfView, zoomMin, zoomMax);
}
}
}
Comment
Try this http://answers.unity3d.com/questions/215425/changing-zoom-speed.html
[1]: http://answers.unity3d.com/questions/215425/changing-zoom-speed.html
Best Answer
Answer by robertbu · Aug 20, 2013 at 04:56 AM
Here is a bit of a rewrite. zoomSensitivity is how much the scrollwheel will zoom per click. zoomSpeed is how quickly the zoom will lerp.
using UnityEngine;
using System.Collections;
public class abc : MonoBehaviour {
public float zoomSensitivity= 15.0f;
public float zoomSpeed= 5.0f;
public float zoomMin= 5.0f;
public float zoomMax= 80.0f;
private float zoom;
void Start() {
zoom = camera.fieldOfView;
}
void Update() {
zoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity;
zoom = Mathf.Clamp(zoom, zoomMin, zoomMax);
}
void LateUpdate() {
camera.fieldOfView = Mathf.Lerp (camera.fieldOfView, zoom, Time.deltaTime * zoomSpeed);
}
}
Thanks you so much, this is extracly what i'm talking about.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112553im_/https://answers.unity.com/themes/thub/images/avi.jpg)