Scoot = Physically Challenged

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

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 on other sites
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 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 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//timestepdouble 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 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 nowstatic 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 ;)

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632997
• Total Posts
3009781
• Who's Online (See full list)

There are no registered users currently online

×