Physics simulation runs half as fast in 30hz

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Physics simulation runs half as fast in 30hz

Post by lazy »

Hi!

I just changed my xbox360 project to run at 30Hz.
Now the physics simulation runs half as fast, even though I update the space with a lower dt. (1/30)
The physics engine seems to ignore my dt and always run at 1/60. Everything else runs as it's supposed to.

Maybe I forgot some propery or something?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Physics simulation runs half as fast in 30hz

Post by Norbo »

If you're using 1/30, it does integer division and truncates to 0. When 0 is used, the engine defaults to 1/60 seconds. To avoid this, you can do something like 1/30f so it does floating point division.
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Physics simulation runs half as fast in 30hz

Post by lazy »

I wish it was so simple. 1/30 was just an example.

I use Game.ElapsedGameTime.TotalSeconds
it is 0.03333333f
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Physics simulation runs half as fast in 30hz

Post by Norbo »

Oh, sorry, I thought you were talking about setting the timestep settings. The value you pass in to the update method is just used to determine the time since the last frame, it doesn't actually integrate the simulation forward by precisely that amount.

The length of time integrated per space update is actually defined by the timestep simulation settings, specifically:

Code: Select all

space.simulationSettings.timeStep.timeStepDuration = 1/30f;

However, one place where the value you pass into the update method is used is in internal time stepping. If you activate it by doing the following:

Code: Select all

space.simulationSettings.timeStep.useInternalTimeStepping = true;
and pass in X seconds to the update method, it will do some number of steps of timeStepDuration length until X seconds are simulated.

Keeping the actual per-integration timestep constant throughout the simulation is necessary to ensure stability, which is why it's in a simulation settings variable as opposed to being directly based on the value passed into the update.
lazy
Posts: 26
Joined: Tue Dec 08, 2009 2:56 pm
Location: stockholm, Sweden
Contact:

Re: Physics simulation runs half as fast in 30hz

Post by lazy »

ah great! Now it works!
thanks!
Post Reply