# object pauses at the each way points for a vary short time

I write this code.

``````var waypoint:Transform [];
internal var  currentWay : int=0;
var TransformSpeed:float;
var duration:float;
var RotationSpeed:float;
function Start () {

}

function Update () {

var target:Transform =waypoint[currentWay];
transform.rotation=Quaternion.Slerp(
this.transform.rotation,target.rotation,Time.smoothDeltaTime*RotationSpeed);
transform.position=Vector3.Slerp(
transform.position,target.position,
Time.smoothDeltaTime*TransformSpeed);

}

function OnTriggerEnter (other : Collider) {
currentWay++;

}
``````

I have an array of way points: “waypoint”.
so my car when trigger each waypoint go the next way point.
but something odd will happen .
the speed of my car isn’t fixed. and each time reach to the waypoint . it is vary slow or even I think stop, and then go vary fast. exactly like our heart Pulse.
" fast->normal->vary slow->fast->…"
in the other word it is not Continuously , like a real car.

I don’t know but I think it is related to the lerp function.
can you help me?

A lerp/slerp function will move your car a fraction of the distance between two points, in this case its current position and its next waypoint. As your car gets closer to each waypoint, that distance gets smaller, so the fraction of that distance that it moves each update is also smaller, and it moves slower. To get a fixed speed, you can can specify a fixed speed, and divide that by the distance left to the next waypoint to get the fraction (t) you need to move this update, something like the example below. Also, you should be using Vector3.Lerp, not .Slerp, as slerp is intended for use with cartesion rotations, not positions.

``````function Update () {

var target:Transform =waypoint[currentWay];
transform.rotation=Quaternion.Slerp(this.transform.rotation,
target.rotation,Time.smoothDeltaTime*RotationSpeed);

var distanceToWayPoint = (target.position - transform.position).magnitude;
transform.position=Vector3.Slerp(
transform.position,target.position,
Time.smoothDeltaTime*(TransformSpeed / distanceToWayPoint));

}
``````