I have the number 0, and every 1/30th of a second, I want to add some number to 0 in order to make it 1 in a specified amount of time. My question is, how do I find the number that should be added to 0 every 1/30th of a second?

For example, if the amount of take it should take for it to add to 1 is 0.1 seconds, you would need to add some number to 0 three times (because 0.1/(1/30) is 3). Again, my problem is that I do not know which number to add to 0 to achieve an end value of 1 after 0.1 seconds.

I've tried doing this every 1/30th of a second: x = specifiedtime/(1/30) y = 1/x 0 + y

Any other ideas will be greatly appreciated


If you want to add to $1$ after $t$ seconds you need to add $\frac {30}t$ every $\frac 1{30}$ seconds. If $t=1$ this is $\frac 1{30}$. If $t=0.1$ this is $\frac 13$. This works perfectly if $t$ is a multiple of $\frac 1{30}$ second. If not, there are rounding errors. For the first, round $t$ down to the nearest multiple of $\frac 1{30}$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.