# detaliled explanation about given Vector3.Slerp example in unity documentation

// Animates the position in an arc between sunrise and sunset.

``````var sunrise : Transform;
var sunset : Transform;

function Update () {
// The center of the arc
var center = (sunrise.position + sunset.position) * 0.5;
// move the center a bit downwards to make the arc vertical
center -= Vector3(0,1,0);

// Interpolate over the arc relative to center
var riseRelCenter = sunrise.position - center;
var setRelCenter = sunset.position - center;
transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, Time.time);
transform.position += center;
}
``````

this is the example given in the unity documentation, its little difficult to understand for a newbie like me, can anyone make it more understand with more simple example. thanks

Maybe this helps a bit (my MSPaint skills are a bit rusty :D)

edit I should have mentioned that this image is only correct if the start and end point is about the same distance from the origin. If they have different length the arc might look strange. I’ve made a webplayer to show this

Here is a shorter example. Attach it to a game object, set the time.

``````private var endPos : Vector3 = new Vector3(2.0, 0.0, 0.0);
private var startPos : Vector3 = new Vector3(-2.0, 0.0, 0.0);
var translationTime : float = 3.0;

private var timer = 0.0;

function Start() {
transform.position = startPos;
}

function Update () {

if (timer < translationTime) {
transform.position = Vector3.Slerp(startPos, endPos, timer/translationTime);
timer += Time.deltaTime;
}
else if (timer >= translationTime) {
transform.position = endPos;
}
}
``````

This code take the initial position of the game object and moves it to the endPos along an arc in the amount of time specified as translationTime. Slerp()'s final parameter is designed to be in the range of 0 to 1. It specifies what fraction the way between startPos and endPos to return. For a value of 0.5, the position will be half way between the two startPos and endPos.