Smooth Camera Rotation

I am developing a game where there are two players that can be switched between. The camera smoothly follows them, and rotates based on the x position of each player. The problem is, when I select my other player to have the camera focus on, the rotation jumps instead of smoothly transitioning.

I’ve heard of Mathf.Lerp, but wouldn’t I need the position of each separate object to do that? Is there an easier way? Here is my basic code.

#pragma strict

var target : Transform; //changes between player 1 and player 2
private var lookAt : float; //because var target is used in another script, I condense the math to var lookAt

function Start () {


function Update () {

target = GameObject.FindGameObjectWithTag(GameManager.currentPlayer).transform;

lookAt = (target.transform.position.x)*2;
transform.localEulerAngles = new Vector3(10,lookAt,0);  //how can I smooth this action when I change the var target?

But you do have the positions!

You want to Slerp or Lerp between your target and the current position of the camera.

Something to the effect of:

transform.position = Vector3.Lerp(target.transform.position, transform.position,Time.DeltaTime);

I would also suggest not assigning the target every single frame, but rather have a method that switches and then you could start the S/Lerp.

From what I see, in your update function you have “target” (being a float) trying to get the location of a Vector3. Try changing “target” to a Vector3.