This question was
closed May 30, 2017 at 06:03 PM by
KillerButter2K for the following reason:
Already figured it out.
Question by
KillerButter2K · May 21, 2017 at 04:32 PM ·
c#inputcharactercontroller
How do I Lerp input floats?
I'm trying to figure out how to use Mathf.Lerp on input floats to create smooth movement for my FPS controller without physics materials. I've tried something like this:
moveX = Input.GetAxisRaw("Horizontal") * speed;
moveZ = Input.GetAxisRaw("Vertical") * speed;
moveX = Mathf.Lerp(0, moveX, Time.deltaTime * smooth);
moveZ = MathF.Lerp(0, moveZ, Time.deltaTime * smooth);
but the movement was still constant. I've also tried this:
moveX = Mathf.Lerp(0, Input.GetAxisRaw("Horizontal"), Time.deltaTime * smooth) * speed;
moveZ = Mathf.Lerp(0, Input.GetAxisRaw("Vertical"), Time.deltaTime * smooth) * speed;
and that still did nothing. If anyone knows, please leave a reply. Thanks
Comment
Answer by Marshal_Alessi · May 22, 2017 at 01:48 PM
Hello my friend! So, you're using Input.GetAxisRaw, which will always be a constant. What you want, is just GetAxis.
moveX = Input.GetAxis("Horizontal") * speed;
moveZ = Input.GetAxis("Vertical") * speed;
This automatically lerps from value to value, instead of instantly changing.
Cheers!
But it only works for the keyboard, not the joystick.