BEPU Physics and FixedTimeStep

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
CatalinZima
Posts: 4
Joined: Fri Aug 01, 2008 11:08 am

BEPU Physics and FixedTimeStep

Post by CatalinZima »

I'm currently experimenting with the physics engine, and there's one thine I noticed.
When using FixedTimeStep for the game, everything works ok.
But when seting IsFixedTimeStep = false, the simulation speeds up, proportional to the framerate.

How can I make the simulation be independent of the framerate (I need to use variable time step)?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU Physics and FixedTimeStep

Post by Norbo »

This is an issue I was going to try and solve in v0.7.0 by adding in an internal time accumulator. This would update the simulation as many times as necessary during a given frame, then fill in the remainder of the frame by interpolating buffered positions forward based on their current velocity.

While running a simulation multiple times in a given frame by accumulating frame durations wouldn't be too hard to do externally, you would still end up with a slight appearance of non-smooth movement. Smoothing it with interpolation would require looking into the velocities and positions and creating your own external, interpolated position that is then used in all your graphics in lieu of the physics data.

The logic itself would function correctly over a period of time without interpolation, though.
nindim
Posts: 10
Joined: Thu Nov 06, 2008 1:40 pm

Re: BEPU Physics and FixedTimeStep

Post by nindim »

I take it you are referring to an insatnce where the framerate exceeds 60fps (In the case of not v-syncing)?

What about if the framerate dips below 60, simply because you're doing too much rendering or effects or whatever. In that case I wouldn't want to do multiple physics simulations per frame, i just want to do one per frame. I understand that you can get unexpected results if the timestep is too great, but at the same time, I don't want a hiccup in my framerate to make the physics look weird (travelling too fast/slow etc).
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU Physics and FixedTimeStep

Post by Norbo »

In v0.6.2 and above with space.simulationSettings.useInternalTimeStepping = true, it will run an appropriate number of simulation frames at a constant timestep per frame (at higher than normal or lower than normal framerates). You can cap the number of these updates by setting space.simulationSettings.timeStepCountPerFrameMaximum to 1 or whatever you'd like, but this would (as you mention) cause a slo-mo effect when your framerate dips.

You can force the engine to use a variable timestep by changing the space.simulationSettings.timeStep every frame prior to space.Update, though things will get ugly pretty quick.

Running the engine in another thread can alleviate these problems to some degree (a holdup on the rendering thread won't force the physics to update a bunch and worsen the situation). Dealing with the synchronization can be a little tricky in v0.6.2 since it all has to be done external to the engine, but v0.7.0 makes things much much more thread-safe.
nindim
Posts: 10
Joined: Thu Nov 06, 2008 1:40 pm

Re: BEPU Physics and FixedTimeStep

Post by nindim »

I may wait for 0.7.0 then :) Ideally my framerate will never dip below 60, but you know how that usually goes ;)
Post Reply