slow a lerp ? array/static problem

basically im using this to snap between 4 different zoom levels of a camera, that works fine, now i can’t get my lerp to work gradually or be “smooth” any insight would be awesome,

i know im kinda of asking people to do it for me, but i just cannot figure out as this is new territory for me, thanks in advance :slight_smile:

#pragma strict
var target : Transform ;
var distance:float = 20.0;
var switchDistance : int;
var height : float = 10.0;
var rotationDamping : float = 1.0;
var rotateSpeed : float = 20.0;
var speed : float = 0.001;
private var heightArray : float[];
private var lengthArray : float[];
private var distanceArray : float[];
 var i :int;//indexes our array values by assigning them a number in our switch case
 
function Start () {
heightArray = [10.0, 20.0 ,30.0,40.0];
lengthArray = [10.0, 20.0 ,30.0,40.0];
distanceArray = [10.0, 100.0 ,150.0,400.0];
switchDistance = 2.0;
 
}
 
function Update () {
    distance = distanceArray*;  //here we actually set i as part of our array* 

if(Input.GetButton(“rightMouse”)){
var h : float = rotateSpeed * Input.GetAxis (“Mouse X”);
transform.Rotate (0, h, 0);
}
switchDistance= Mathf.Clamp(switchDistance,0.0,4.0);
distance = distanceArray*;*
height = heightArray*;*
}

function LateUpdate() {
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.transform.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;

if (Input.GetAxis(“mouseZoom”)>0 && switchDistance <=4 ){
Debug.Log(“+”);
switchDistance -= 1 ;

}
if (Input.GetAxis(“mouseZoom”)<0 && switchDistance >=0){
switchDistance += 1 ;
}

switch (switchDistance){

case 3:
//distance = 75.0;height = 15; break;

//transform.position.x=Mathf.Lerp(heightArray[3],heightArray[3],Time.time);Debug.Log(“case3”);break;
i= 3;transform.position.x=Mathf.Lerp(distanceArray[3],distanceArray[3],Time.time*speed);Debug.Log(“case3Lngth”);break;
case 2:

//transform.position.x=Mathf.Lerp(heightArray[2],heightArray[3],Time.time);Debug.Log(“case2”);break;
i=2;transform.position.x=Mathf.Lerp(distanceArray[2],distanceArray[3],Time.time*speed);Debug.Log(“case2Lngth”);break;

case 1:

//transform.position.x=Mathf.Lerp(heightArray[1],heightArray[2],Time.time);Debug.Log(“case1”);break;
i=1;transform.position.x=Mathf.Lerp(distanceArray[1],distanceArray[2],Time.time*speed);Debug.Log(“case1Lngth”);break;

case 0:

//transform.position.x=Mathf.Lerp(distanceArray[0],distanceArray[1],Time.time);Debug.Log(“case0”);break;
//transform.position.z=Mathf.Lerp(lengthArray[0],lengthArray[1],Time.time);Debug.Log(“case0Lngth”);break;
i= 0;transform.position.x=Mathf.Lerp(heightArray[0],heightArray[1],Time.time*speed);Debug.Log(“case0Lngth”);break;
}

currentRotationAngle = Mathf.LerpAngle(currentRotationAngle,wantedRotationAngle,rotationDamping*Time.deltaTime);
var currentRotation = Quaternion.Euler(0,currentRotationAngle,0);
transform.position = target.position;
transform.position -= currentRotationVector3.forwarddistance;
transform.position.y = wantedHeight;
transform.LookAt (target);
}

There are two ways you can approach this problem. The first is a “misuse” of Lerp() that is commonly used and results in an easing of the movmenet:

transform.position.x=Mathf.Lerp(transform.position.x,distanceArray[3],Time.deltaTime*speed);

The second is more traditional. It involves you building a timer. The timer gets reset to 0 at the beginning of the movement and then is incremented at every Update() call:

timer += Time.deltaTime;
transform.position.x=Mathf.Lerp(distanceArray[2],distanceArray[3],timer*speed);

Note that the last parameter in the Lerp() call is a fraction between 0 and 1. When the value is 0, it will be at the first position. When the value is 1 it will be at the second position. Except for a brief time at the beginning of the game, Time.time will always be greater than 1.0.