- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
tekke · Apr 30, 2013 at 03:59 AM ·
mathfincrementmathf.lerp
Increment a float Value from A to B in N seconds
Hello people, as the tittle indicate , i'm trying to increment a int value from value A to a value B in a N amount of seconds ,
void Update()
{
if (bDiveDelay)
{
iPlayerSpeed = Mathf.MoveTowards (fDiveMagnitude, iSpeedInter, 5 * Time.deltaTime);
print ("speed es " +iPlayerSpeed);
}
if (iPlayerSpeed == iSpeedInter)
{
bDiveDelay = false;
}
}
i'm trying to increment my iPlayerSpeed from the value fDiveMagnitude to iSpeedInter in a certain amount of time , but it doesnt work , it start adding numbers to the value but it never reaches the value of iSpeedInter , I also tried thi with mathf.Lerp, and got same result. Any help/ comment will be really appreciated, thanks for your time
Comment
Best Answer
Answer by sparkzbarca · Apr 30, 2013 at 04:12 AM
you should do something like
playerspeed = mathf.lerp(playerspeed,desiredspeed, speed * time.deltatime);
basically the first value should be the same as what your changing
if the first value is constant your speed won't change.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101251im_/https://answers.unity.com/themes/thub/images/avi.jpg)