- Home /
Increase as timer decreases
Hello
So I want to make the speed increase as the timer goes down, but I don't know how to calculate it and code it. The timer starts at 120 The speed starts at 0
When the timer reach 0 The speed needs to be 2
But the speed needs to increase as the timer goes down.
Example: Timer=20 Speed=0
Timer=19 Speed=0.2
Timer=0 Speed=20
Thanks
Answer by HarshadK · Dec 03, 2014 at 09:38 AM
The formula you can use for calculating the current speed based on current value in the timer is:
speed = ((max timer value - current timer value)/max timer value) * max speed value.
Here,
max time value = 12 and max speed value = 2
Now substitute in the equation at timer value 100:
speed = ((120-100)/120) * 2 = 0.33
So your speed at timer value 100 is 0.33
Just to note this is percentage based increase.
Hello you method worked perfectly, i just have one more question. when i add the increasing speed to the normal speed how can i add the two together.
playerSpeed = 4 increasedSpeed = 0.33
4x0.33 = 1.32 what i want is 4.33
my code calculation goes like this
vector3 x playerSpeed (add increasedSpeed)
thanks
Just add the two values like:
Vector3 x (playerSpeed + increasedSpeed)
Your answer
Follow this Question
Related Questions
UI Panel Don't Destroy On Load? 2 Answers
Time does not start counting down when need to 1 Answer
How do I get remaining time to display on screen? 1 Answer
Timer Script Not Keeping Accurate Time? 1 Answer
Timer Data Across Scene Changes 1 Answer