How do I fix objects "popping" or jittering in physics engine?

| | August 8, 2015

I’ve got a simple physics engine that solves collisions by simply correcting the position of overlapping bodies (just circles for now) directly, as opposed to just changing the velocity or applying an impulse. Velocity is only changed after impacts are already resolved, or during the integration part.

I’ve had the problem that in heaps of objects the top objects apply too much pressure (this exists implicitly, there’s no pressure modelling in the algorithm) on the objects at the bottom of the heap, which results in them getting pushed through floors, etc.

I wanted to fix this by sorting the objects by their y-coordinate, so the collisions are resolved bottom-up. But now, the engine shows weird popping behavior for objects which should actually be at rest (see gif)

enter image description here

Without just giving you the source code – what could this be?

One Response to “How do I fix objects "popping" or jittering in physics engine?”

  1. One solution I have found when using position correcting is to have a few iterations and vary the strength with each iteration.

    int num_iterations = 5;
    for(int iteration=0; iteration<num_iterations; ++iteration)
        float strength = float(iteration+1)/num_iterations;

    So the first iteration has a strength of 1/num_iterations and the last has a strength of 1. This makes my simulations smoother and more stable than simply using the same number of iterations with a fixed strength.

Leave a Reply