Game Development Community

Frame rate Independent?

by Chris Cockcroft · in Torque Game Builder · 02/09/2006 (6:24 pm) · 3 replies

Hey,

I'm playing around with the new beta (1.1) on my iBook G4, and am getting some weird issues with varying frame rates and the physics system.

It used to be when I ran a high resolution, my frame rate would drop and the game would be a little choppy. However, the sprites would move at the same rate as they would with a higher frame rate. Now, everything in my game slows down when the framerate drops, and speeds up when the framerate rises (sometimes to an uncontrollable level).

Is the physics system no longer frame rate independent? Or am I missing a setting?

Thanks for any help :)
Chris

#1
02/09/2006 (6:29 pm)
Hmmm... now that I think about it, I update my impulse velocity in onSceneUpdate. I guess if the frame rate drops, so does the number of scene updates per second. I guess I'll need to rework a few things.

Is there a way to call aan update function a specific number of times per second that would be independent of the frame rate? Are schedules the only way?

Thanks again :P
Chris
#2
02/11/2006 (7:52 am)
Well, I certainly wouldn't be doing lots of impulses every second as it begs the question why not just do less with slightly bigger impulses but if this isn't the case here, I guess a way to achieve this would be to use the periodic timer available on every "t2dSceneObject" e.g. "setTimerOn()" and "setTimerOff()".

Good Luck,

- Melv.
#3
02/11/2006 (9:19 am)
I think the right thing to do is not to update physics in framerate-based code,
but if you do, there's a couple options -

you can do the math to account for the framerate, eg
// secondsPerFrame = 1.0 / framerate;
impulse = impulsePerSecond * secondsPerFrame;
- this can get tricky if your math is heavily non-linear.


or you could write what you suggested, a way to call a function a specific number of times per second, independent of framerate.
i wrote one of these once, i think i called it a framerate normalizer.
usint it looked like this:
...
myFramerateNormalizer.desiredTicksPerSecond = 30;
...

someFrameRateDependentFunction()
{
   numTicksNeededThisFrame = myFramerateNormalizer.howManyTicks();
   for (i = 0; i < numTicksNeededThisFrame; i++) {
      foo.tick();
   }
}

i forget the implementation of howManyTicks() ;)
but i don't think it was very tricky.