Does CharacterController benefit from adding lerp?

by TeachMeEverything   Last Updated May 16, 2019 02:13 AM

Does CharacterController benefit from adding lerp?

as in this script.

mouse = Input.GetAxis("Mouse X");
current = Mathf.Lerp(current, mouse, Time.deltaTime * 10);
transform.Rotate(0, current * 600 * Time.deltaTime, 0);

I was using,

transform.Rotate(0, mouse * 18, 0);

But read into the idea of lerp and wrote that.



Answers 1


As a general practice, find a problem before you try to solve it.

There are lots of solutions in game development, and many of those solutions are for problems that you do not have.

Reaching for a solution before you know if there's a problem or what it is can lead to:

  • wasted work (you didn't have a problem at all, now you've spent time for no benefit)

  • sub-optimal solutions (you missed an opportunity for a better solution for your specific case)

  • creating new problems (this solution is so ill-fit for the current situation that it actually makes it worse)

The specific example you have here looks like one of the "creating new problems" variety.

Here you're taking the player's mouse input, and instead of using it to immediately turn their camera in exact proportion to their movement to make their control tight & responsive, you are adding a layer of indirection.

The variable current will seek toward mouse (at an inconsistent rate when running at different frame rates, since you used Time.deltaTime incorrectly in your third Lerp argument), but always lag behind it:

  • if I move sharply to the right, current will increase by only a fraction of my movement: I have to make an exaggeratedly large movement to get the response I intended.

  • if I keep moving to the right at a constant speed, current will gradually increase closer and closer to my actual input value, by smaller and smaller intervals each time. So to turn at a constant rate, I actually have to start moving fast then slow down my arm to avoid over-accelerating.

  • if I stop moving, current will continue to have a positive value and the camera will keep spinning for several frames. So I have to stop early and hope the camera will come to rest somewhere near where I want it.

This will tend to make your controls feel spongy, laggy, and non-responsive, or even outright sloshy and motion sickness inducing.

So no: don't do this.

Lerp isn't your "make stuff smoother" sauce. It's a math function that blends two values. First, understand what values you're working with and whether it's appropriate to blend them, before reaching to Lerp or another method.

DMGregory
DMGregory
May 20, 2019 13:47 PM

Related Questions


Updated November 17, 2017 00:13 AM

Updated May 26, 2016 08:05 AM

Updated February 19, 2016 01:05 AM

Updated April 24, 2016 08:05 AM