Jump to content
  • Advertisement
Sign in to follow this  
ScootA

Scoot = Physically Challenged

This topic is 4724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been integrating Novadex into my game engine, and it was all working fine... until I added something to my test which reduced the framerate noticably. Then I started noticing things weren't moving at the correct speed. That was two days ago and i'm going slightly insane :S. I'm just not sure how to maintain a constant simulation - i'm adding forces to bodies each frame, and when the framerate changes, the forces have different effects on the simulation (speed up/down). I realise that you need to pass in a different timestep into the simulate function depending on the framerate, but do I also need to scale the forces i'm applying to my bodies each frame? Any help would be greatly appreciated...

Share this post


Link to post
Share on other sites
Advertisement
One of the easier ways to achieve framerate independence is to have your physics run at a fixed timestep and then just interpolate between frames if display is running at a different rate. It's not that hard to implement and it's been discussed on the forums quite often.

Share this post


Link to post
Share on other sites
Actually, you do not have to pass in a varying frame rate. And, if you carefully read the NovodeX documentation, you will see that they recommend you do not. You basically pick a fixed time step, then for each frame (which has a varying amount of time from the prior frame), call the physics integrator enough times for the physics to catch up with the actual, variable frame rate. This is going to make it easier to produce consistent results and keep your simulation stable.

In general, your forces should have nothing whatsoever to do with frame rate or time step. They are functions of the instantaneous object position, orientation, velocity, angular velocity regardless of the time step being used. Now, you might be trying to design a special effect in which the physics is affected by time step. If so, this is extremely unusual and I can't begin to say what trouble you might be getting into by doing this, :).

Share this post


Link to post
Share on other sites
First off - thanks for the quick replies.

So should I perhaps be doing something along the lines of:


double nElapsedTime = //time elpased since last call of physics loop

//timestep
double nTimeStep = 1000.0/60.0;

int nStepsToPerform = nElapsedTime / nTimeStep;

for (int cStep=0; cStep<nStepsToPerform; cStep++)
cScene->simulate(nTimeStep);

//do checkresults etc...




Im not sure if I need to do the check/fetch results every inner loop.

Share this post


Link to post
Share on other sites
Basically, yes, although you might want to keep track of the rounding error in that division you do, otherwise you will find some people loosing out on a physics frame every so often.

I solve this by leaving the division out completely, keeping a variable for the time my physics engine has reached, and incrementing that variable until it reaches the current frame time.


double currentTime = // whatever the game time is now
static double physicsTime = 0.0f;
double nTimeStep = 1000.0/60.0;

while (physicsTime < currentTime)
{
cScene->simulate(nTimeStep);
physicsTime += nTimeStep;
}




except physicsTime would be a class member, not a static ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!