# Lerp can someone explain please

okay, so I’ve been trying hard to get my charactercontroller to lerp between it’s current position and a position some distance away in the x direction. I have it to where it works now, except that it happens instantly. I would like a smooth transition, but it seems like nothing works, and when I follow others advice I end up with error codes that are impossible to resolve. There is NOT a lot of info on this subject, and the game engine doesn’t recognize algebraic functions that dictate velocity over time.

could someone please fill me in on how to do this. any information or advice is helpful.

You have a couple options, some not built into unity:

First, Ill explain how lerp works:
Ill use Mathf.lerp for ease of understanding
This is what Lerp basicly does internaly

SUDO CODE:

``````float Mathf.lerp(float from, float to,float percent){
differnce =  to - from;
return = from + (differance*percent);
}
``````

So in otherwords, If you feed in 0.10 or 10%
Lerp will move the from 10% closer to the to;
so the thing to remember is the distance it moves gets smaller and small…
IE: Lerp(100,0,0.1) = 90 , Lerp(90,0,.1) = 81 , Lerp(81,0,.1) = 72.9 , etc , etc

You may want to use Vector3.movetowards or Mathf.moveTowards
you put in a from, and to positions, but instead of a % along path, it will never move faster than the speed you feed into it;

finanaly if you need a different solution such as smooth out, and smooth in. You may want to check out iTween : iTween for Unity by Bob Berkebile (pixelplacement)

you also said:

There is NOT a lot of info on this
subject, and the game engine doesn’t
recognize algebraic functions that
dictate velocity over time.

Also, to address this, You have to build you velocity over time around the update loop, meaning, you ether need to track time yourself using Time.time or Time.deltaTime or System.DataTime.Now

IE:

``````public Vector3 myWorldVelecoity = new Vector3(10,0,0); //Move along the world X at 10 units per second
public void Update(){
this.transform.Translate(myWorldVelecoity * Time.deltaTime);
// OR
this.transform.position = this.transform.position + (myWorldVelecoity * Time.deltaTime);
}
``````