Why is my camera zoom min and max changing?
I have implemented camera zoom via the "Mouse ScrollWheel" axis. There is a minimum and a maximum zoom level, and the camera starts in the middle. The zoom stops when it reaches the max or min. However, the zoom max and min zoom level changes slightly almost every time it's reached. In other words, each time I zoom the camera in to its max zoom level, it's a slightly different distance from the objects in the scene.
In my input controller's Update() method, I have this code:
if(Input.GetAxisRaw("Mouse ScrollWheel") != 0)
{
cameraController.Zoom(Input.GetAxisRaw("Mouse ScrollWheel"));
}
This is my camera controller's Zoom() method:
public void Zoom(float scroll)
{
float oldZoom = zoom;
zoom = Mathf.Clamp(oldZoom + scroll, zoomMin, zoomMax);
float moveAmount = zoom - oldZoom;
transform.Translate(Vector3.forward * moveAmount * zoomSpeed * Time.deltaTime);
}
What's causing this, and how can I prevent it?
Comment