# How to use Lerp?

I am confused on how exactly to use the Lerp function. I am using the function as Slerp in the following code:

example 1:

``````selfplace.rotation = Quaternion.Slerp(selfplace.rotation,Quaternion.LookRotation(target.position-selfplace.position),MarManRotateSpeed * Time.deltaTime);
``````

example 2:

``````selfplace.rotation = Quaternion.Slerp(selfplace.rotation,Quaternion.LookRotation(target.position - selfplace.postition),MarManRotateSpeed * Time.deltaTime);
``````

Lerp is a linear interpolation, whereas Slerp is a spherical interpolation.

In the first case, the interpolated point will ‘move’ from the first to the second argument along the segment formed by these two points.

In the second case, the interpolated point will ‘move’ from the first to the second argument along the sphere surface which center is calculated so that the first and second argument belong to the arc.

static function Lerp (from : float, to : float, t : float) : float
Description
Interpolates a towards b by t. t is clamped between 0 and 1.

When t = 0 returns from. When t = 1 return to. When t = 0.5 returns the average of a and b.

JavaScript
// Fades from minimum to maximum in one second

var minimum = 10.0;
var maximum = 20.0;

function Update () {
transform.position = Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0);
}

As far as i know, lerp/slerp must be called in every frame if you want effect.

Btw. are you sure that “selfplace.postition” is an existing property?