How to use Lerp?


I make a platformer game. the camera follows the player in the X axis with a little offset of 7 units. I made a script to change this offset accordingly to the direction the player is moving. How can I smooth the transition between the two positions of the camera??

Circle = camera

Polygon = Player

alt text

#pragma strict
var player : Transform;
var reverse : boolean;

function Update () {
		transform.position.x = player.position.x + 7;
		transform.position.x = player.position.x -7;

Here is one way to use Lerp:

 transform.position.x = Mathf.Lerp(transform.position.x, player.position.x + 7, speed * Time.deltaTime);

You will need to define and initialize ‘speed’.