- Home /
Mathf.Lerp skips numbers
I have a very simple, virtually empty scene, so lagging isn't a reason, but when using Mathf.Lerp as follows:
if(Input.GetKeyDown("space")){
grow = true;
}
if(grow){
size = Mathf.Lerp(40.0, 100.0, growthSpeed*Time.time);
}
It skips between 10 and 20 straight away! rather than starting from 40 and counting up it starts immediately between 50 and 60 then continues counting slowly! (growthSpeed is 0.1) and size starts at 40. I don't understand why it's skipping like this! Any ideas?
thanks in advance!
Answer by robertbu · May 12, 2014 at 04:59 PM
Your results will vary depending on how quickly you hit the space bar. The third parameter of a Lerp() needs to be in the range of 0.0, and 1.0. So here is an alternate solution.
Set your 'growthSpeed' to 1.0, initialize size to 40.0, then change line 5 to:
size = Mathf.MoveTowards(size, 100.0, growthSpeed*Time.deltaTime);
'growthSpeed' will now be units per second.
$$anonymous$$agic! thank you very much works a charm! and great quick response
Your answer
![](https://koobas.hobune.stream/wayback/20220613144857im_/https://answers.unity.com/themes/thub/images/avi.jpg)