Page 1 of 1
Physics simulation runs half as fast in 30hz
Posted: Sat Dec 12, 2009 11:57 am
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?
Re: Physics simulation runs half as fast in 30hz
Posted: Sat Dec 12, 2009 4:41 pm
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.
Re: Physics simulation runs half as fast in 30hz
Posted: Sat Dec 12, 2009 6:22 pm
by lazy
I wish it was so simple. 1/30 was just an example.
I use Game.ElapsedGameTime.TotalSeconds
it is 0.03333333f
Re: Physics simulation runs half as fast in 30hz
Posted: Sat Dec 12, 2009 8:57 pm
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.
Re: Physics simulation runs half as fast in 30hz
Posted: Sat Dec 12, 2009 11:05 pm
by lazy
ah great! Now it works!
thanks!