# For timed levels, how do you determine time steps that are less than 1/(frames per second)?

I have made a simple HTML5 racing game. The laps are timed. I am running the game are 40 frames per second, each frame represents 40 milliseconds. There for my timer will increase in 0.025 increments.

My question is how can I get my timer to record lap times more accurately, without running at 100 frames per second! How do other games do it? Could it be to do with gauging the distance from the car to the finish line in the frame before and after it crosses the finish line?

-
At 40fps your timesteps are 0.025 second increments. – user744 Jul 7 '11 at 23:40
Fixed, sorry about that! Question still remains though, thanks for spotting – Moz Jul 7 '11 at 23:46

Your own proposed answer is spot on; to determine the finish time for a car, you take its position on the frame before finishing and its position on the frame after finishing, and determine at what point during that frame it actually crossed the finish line.

If (for example) it crossed the finish line at 40% of the way from its previous position to its next position, then you only add 40% of the timestep value to determine the finishing time.

Assuming that your finish line is a straight line, and treating the player's movement from one frame to the next as a straight line, you can easily find where (and then, when during the frame) they crossed by solving a line intersection test.

-

Okay first off, I don't know how you think you are running 40 frames per second with each frame being 40 milliseconds. 1 second = 1000ms. 40ms per frame gives you an FPS of 25. If you want to actually be at 40 FPS you are going to need to have a timestep of 25ms per frame.

Most racing games run with the car physics at a really high frame rate. One example would be Forza 3, it more sim like than most games, and its physics runs at 360 hertz.

So using a frame rate that is higher than your update rate could work, although with java-script you may be limited with performance.

If you really need to run at 40 FPS, I see no problem with creating a function that you can plug in the current time, and the distance, and have it return an estimated time.

-
Downvote? Did I say something wrong? Tell me what I should change? – AttackingHobo Jul 8 '11 at 15:59