Zooming with a gun problem (C#)

Hi all,

I’m trying to do a zomming features on my game and I got a problem …

Got this in my MouseLook C# script attached to my Camera :

	//zooming variables
	public float defaultCameraAngle = 60.0f;
	public float currentTargetCameraAngle = 60.0f;
	public float ratioZoom = 1.0f;
	public float ratioZoomV; 
	public float ratioZoomSpeed = 0.2f; 

    //some stuff

		if (Input.GetKey(playerInputsComponent.aiming) == false) { //right click
			ratioZoom = Mathf.SmoothDamp (ratioZoom, 1, ref ratioZoomV, ratioZoomSpeed);
		}
		else {
			ratioZoom = Mathf.SmoothDamp (ratioZoom, 0, ref ratioZoomV, ratioZoomSpeed);
		}
	
		camera.fieldOfView = Mathf.Lerp(currentTargetCameraAngle, defaultCameraAngle, ratioZoom);

And got my weaponScript attached to my weapon :

	//zoom
	public float zoomAngle = 30;

    //lot of stuff

cameraObject.GetComponent<SmoothMouseLook>().currentTargetCameraAngle = zoomAngle;

So when I pressed the right click it’s supposed to zoom smoothly to 30 degress FOV but it zoom without stopping down to 0 and it varies between 0 and 10…

Can someone help me please ? I don’t understand what happens…

Hope you understand the problem, thanks in advance!

Lerp returns 1 single interpolated value each time you call it.

To create a smooth motion you vary t from 0 to 1 and call Lerp repeatedly. It’s best performed in Update.