Camera chasing player

I want the camera to follow the player and lag a little bit and then catch up with the player when the player halts. When stopped the player is in the center.

At the moment im at the point where i get the camera to move with the player but i dont know how to get the lag effect!

On the camera object

    void Update () {
    var newX =  player.transform.position.x;
    var newZ =  player.transform.position.z;
    var y = transform.position.y;
    transform.position = new Vector3(newX, y, newZ);    
}

just a delay or with increasing speed? maybe somethin like this? (not tested, sry) var delay = 0.6; var dT = Time.deltaTime / delay; transform.position = Vector3.Lerp(transform.position, new Vector3(newX, y, newZ), dT);

1 Answer

1

I suggest you look at the SmoothFollow script from Standard Assets. That uses some rotation damping and height damping so that the camera smoothly follows the player. You can duplicate the height damping (Y) for X and Z to add lag on the cameras position.