# How can I invert lerp or just make smooth moves?

I want to be able to move an object to the position of the player in a smooth fashion. Lerp would be good in this form:

var start : Transform; var end : Transform; function Update () { transform.position = Vector3.Lerp(start.position, end.position, Time.time);

but the object always arrives at its destination in the same amount of time no matter the distance. I need the object to be moving on average at a constant velocity.

This form would be better:

var target : Transform; var smooth = 5.0; function Update () { transform.position = Vector3.Lerp ( transform.position, target.position, Time.deltaTime * smooth);

..giving it a realistic speed up slow down touch. However in this form it slows down the closer it gets to its target. I would like it to be slower at it leaves its position and speed up a bit to a constant velocity on its approach to its target

basically I would like to know how to make my object speed up to constant velocity and then slow down. How can do i do that? how to I make an object speed up?

Thanks a ton!

Use a coroutine like this:

``````var start : Transform;
var end : Transform;
var speed = 2.5;

function Start () {
yield LerpPosition (start.position, end.position, speed);
}

function LerpPosition (start : Vector3, end : Vector3, speed : float) {
var t = 0.0;
var rate = 1.0/Vector3.Distance(start, end) * speed;
while (t < 1.0) {
t += Time.deltaTime * rate;
transform.position = Vector3.Lerp(start, end, Mathf.SmoothStep(0.0, 1.0, t));
yield;
}
}

``````