Small objects or intense gravity and jitters

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ryantrem
Posts: 5
Joined: Sun Nov 14, 2010 11:12 pm

Small objects or intense gravity and jitters

Post by ryantrem »

I'm trying to use Bepu physics to simulate small objects (on the order of 2cm). It seems like I should be able to either make my objects really small, adjust various simulation parameters (collision margins, penetration, etc.), adjust various render parameters (view frustum near plane, etc.), *or* I should be able to just increase a few simulation parameters (like gravity) to fake it (I guess this is just changing the units of my environment). Is this assumption correct (sorry, I'm new to Bepu and rusty on physics!)? I've experimented with this a bit, but when I increase gravity, my objects "jitter" for several seconds before settling down. Are there some additional parameters I need to adjust to reduce this jittering?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Small objects or intense gravity and jitters

Post by Norbo »

I would go with the increased gravity approach. The engine likes normal-sized units (0.5 to 10 is a very safe range for entity dimensions), whereas going down to actually 0.02 units would require retuning of a lot of other collision detection features.

The reason why you see jitter when increasing the gravity to compensate is that it is almost equivalent to increasing the overall simulation rate by a factor of 10(assuming you increased your gravity by x10). Each step is jumping over a large section of simulation time, which is very hard to handle.

You could increase the update rate to compensate, though this is going to be proportionally more expensive. The settings to be changed are in the Space.SimulationSettings.TimeStep class. The TimeStepDuration defaults to 1/60f; you may want to try 1/300f or even lower (depending on how small everything is and how high gravity is). To make it run in real time, you could either call the space.Update method repeatedly, or set the TimeStep settings UseInternalTimeStepping to true. This will make the engine call Space.Update internally enough times to keep up with whatever amount of time passes.

Enabling continuous collision detection may let you get away with bigger timesteps. This can be found in the Space.SimulationSettings.CollisionDetection settings. The CollisionDetectionType can be set to DiscreteMPRGJK (the default), or a couple of continuous options (LinearContinuous, FullyContinuous). Increasing the CollisionResponse iteration count might be useful too. Both of these things will add some overhead to each simulation step, while possibly allowing you to take less simulation steps overall.
ryantrem
Posts: 5
Joined: Sun Nov 14, 2010 11:12 pm

Re: Small objects or intense gravity and jitters

Post by ryantrem »

Thanks for the info! I tried all of these things, but none seemed to make a difference. However, when I reduced the bounciness to 0, the jitters stopped. It seems that if I increase the gravity *and* have objects with some bounciness, then I get the jitters I described. Are there parameters to control the threshold for objects bouncing?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Small objects or intense gravity and jitters

Post by Norbo »

Yep, in the Space.SimulationSettings.CollisionResponse, there's a BouncinessVelocityThreshold. For contact velocities below this threshold, no bounce will occur. Higher gravity would indeed benefit from a higher threshold (it defaults to 1).
ryantrem
Posts: 5
Joined: Sun Nov 14, 2010 11:12 pm

Re: Small objects or intense gravity and jitters

Post by ryantrem »

Great, that worked like a charm. Thanks for helping me get this sorted out so quickly!
Post Reply