Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
All in all, this is similar to solving a linear system of equations in an iterative manner (or nonlinear system, depending on your constraints/conditions/etc). Either case, you're seeing these artefacts because they're numerically the correct thing to see: intermediate states of a converging process. Avoiding this is quite tough and could imply a lot of nasty hacks (anyway, this happens in real life, at a molecular level, and that's what you have there to best resemble something in real life :) ). It's probably good to investigate box2d to see their solution for impulse based dynamics. –  teodron Apr 17 '13 at 7:54
@TravisG how did you solve the problem? I'm looking at a similar problem when trying to implement a very simple physics engine. –  cheeesus Dec 12 '13 at 19:24
@cheeesus It's been a while since I worked on it, but I believe I just used more iterations with smaller timesteps. –  TravisG Dec 12 '13 at 19:41
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.