code using lerp with input

Still a beginner playing around with code. Right now this one:

var offset:float;

function Update () {

if (Input.GetKey("d")){ 
YMovement(15,.1);
}
if (Input.GetKey("a")){ 
YMovement(-15,.1);
}
}

function YMovement(b,c) {

    transform.position = Vector3(0,Mathf.Lerp(transform.position.y, b, c), 0);
    Debug.Log(c);
}

so from looking at the code, I should be able to press d and a and see the box go straight up and down. I get that result, but the box slows down as it gets close to 15/-15 ...can someone explain to me why it's doing that? also, how do I use the lerp function for something like this without having it slow down before stopping.

Thanks!

2 Answers

2

See here: http://answers.unity3d.com/questions/6949/can-someone-explain-how-using-time-deltatime-as-t-in-a-lerp-actually-works/6950#6950

facepalm thanks

You might also want to consider using Input.GetAxis("Horizontal").

This has built in smoothing that solves some of the problems you are facing now

thanks. Yeah, I know about Horizontal, I was just playing around with lerp, trying to get a hang of them.