- Home /
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!
Answer by Atnas1010 · Nov 04, 2010 at 04:28 AM
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.
Your answer
Follow this Question
Related Questions
Is it possible to continue a method after Input? 2 Answers
Moving an object from it's current position to the position of the mouse cursor. 0 Answers
How to move object from existing position to new position and change its animation? 1 Answer
Learning to move 1 Answer
Controlling parent by Inputs 1 Answer