What is the standard accepted way to incorporate deltaTime with a mathf lerp like this:
public float testNumber = 0;
void Update()
{
testNumber = Mathf.Lerp(testNumber, 150, .1f);
}
What is the standard accepted way to incorporate deltaTime with a mathf lerp like this:
public float testNumber = 0;
void Update()
{
testNumber = Mathf.Lerp(testNumber, 150, .1f);
}
In your case you need to multiply .1f with Time.deltaTime.
AHHHH, I knew it was something simple like that, thank you!!!
This depends on your desired “curve”.
If you want to have the curve “spring” toward the target value - starting moving fast immediately and then ease towards it at the end, then what you have will more or less work.
However, it won’t be consistent with varying framerates; a slower machine will lerp towards the target more slowly. Multiplying it with Time.deltaTime doesn’t quite do the trick either in this case. It actually has the opposite effect; a high framerate will approach the target more slowly than a low framerate.
To make it framerate independent, you have to do a little math:
testNumber = Mathf.Lerp(testNumber, 150f, 1f - (1f / (lerpSpeed * Time.deltaTime) + 1f));
That formula will get you a consistent % of the way towards the target in a given time period, regardless of the current framerate. lerpSpeed is a constant, and probably should be around 5ish or higher (which will get you a little over 90% in one second).
If your goal is a constant movement, you can either: