- Home /
Slowly decreasing a float
I want to slowly decrease a float, kinda something like Time.deltatime.
I tried "speed--;" but its way to fast.
I want to decrease it from something like 2 to 0 really slow, is there a fast and easy way to do this in c#?
Thanks you for reading!
Answer by rutter · May 23, 2012 at 07:12 PM
In your Update() function, you could run something like this:
speed = Mathf.Clamp(speed - acceleration * Time.deltaTime, minSpeed, maxSpeed);
If acceleration
is positive, speed will increase by that many units per second; if negative, it'll decrease. You could use 0 and 2 for minSpeed
and maxSpeed
.
Answer by lyzard · May 24, 2012 at 06:49 AM
maybe you want something simpler than what proposed rutter ? something as simple as: speed -= 0.1f
which is equivalent to speed = speed - 0.1f
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Float var to control animation speed? 1 Answer
Return 2 FLOAT from 1 VOID 1 Answer
Animation.CrossFade help please 3 Answers