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?
}