- Home /
Question by
smirlianos · May 25, 2014 at 01:05 PM ·
cameralerpplatformersmoothoffset
How to use Lerp?
Hello,
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
#pragma strict
var player : Transform;
var reverse : boolean;
function Update () {
if(!reverse)
{
transform.position.x = player.position.x + 7;
}
else
{
transform.position.x = player.position.x -7;
}
}
preview.jpg
(53.7 kB)
Comment
Best Answer
Answer by robertbu · May 25, 2014 at 02:48 PM
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'.