Lerping between Camera Paths

Helloooo

I have a camera with different iTween Paths on it

I am simply jumping back and forth by activating and deactivating them…

It’s crude, I know, but it’s actually the best solution so far…

But I want the Camara to LERP between the two paths instead of just Jumping immediately.

Here is the C# code so far:

Thanks for looking

using UnityEngine;
using System.Collections;

public class switchITween : MonoBehaviour {

	
	Vector3 firstCam;
	Vector3 secondCam;

	void OnMouseUp() {
		// these are a bunch of Path scripts on the main camera that I am activating and deactivating 
		FlythroughCameraController1 a;
		FlythroughCameraControllerA b;
		a=Camera.mainCamera.GetComponent<FlythroughCameraController1>();
		b=Camera.mainCamera.GetComponent<FlythroughCameraControllerA>();

//		float i = 0.0f;
//		float rate = 1.0/Time;


// These Activate and deactivate the path scripts, but I want that camera not just to JUMP to the newly active payh but Lerp there
		if (a.enabled == true) {
		Debug.Log ("B");				
		a.enabled = false;	
		b.enabled = true;
//			while (i>1.0) { 
//				i += Time.deltaTime * rate;
//				Camera.main.transform.position = Vector3.Lerp(firstCam, secondCam, i);
//
//			}
		}
//
//
//
		else if (b.enabled == true) {
		Debug.Log ("A");
			b.enabled = false;
			a.enabled = true;
//			while (i>1.0){ 
//				i+= Time.deltaTime * rate;
//				Camera.main.transform.position = Vector3.Lerp(secondCam, firstCam, i);
//
//				}
			}
//
	}
}

Vector3.Lerp function’s third parameter is a number between 0 and 1. It looks like you dont execute unless i is already above 1 therefore the Lerp function doesn’t have a chance to interpolate between your two points. Also, OnMouseUp is called once and Lerping is usually best done over several frames otherwise your camera will just go part ways to the second point and stop. So what I would suggest is using

while(i < 1.0f) {
    i+= Time.deltaTime * rate;
    Camera.main.transform.position = Vector3.Lerp(secondCam, firstCam, i);
}

Hope this helps! Good luck :slight_smile: