Open leaf-node opened 8 years ago
Hi, We all want the overlap to be as small as possible :) Even thought the stiffness has a role in this problem, the time step size is probably worse.
To move bodies forward in time, this is the formula used:
x += v * dt
Let's say you have a configuration where a body is very close to another body, but not overlapping. The body is moving towards the other body with a velocity v
. Next time step, the bodies will overlap by v * dt
length units, no matter the value of stiffness
.
If you're lucky, your configuration will yield some smaller overlap. If you choose the time step parameter to be small, you can make the overlaps smaller.
You can also make sure to limit the velocities of things in the world (this is a common gamedev trick). For example, less gravity value will give you less speedy objects.
Related is the experimental CCD feature in p2. But this is only helps if your objects move VERY fast. What it does is choosing a time step so that the bodies move forward to the time of impact and not more. It's sequential and slow, and not energy preserving, so it's probably not a solution for you.
// CCD
x += v * timeOfImpact
This type of error seems fine to me, as long as I set the interval low enough.
What about cases where stacked circles occasionally overlap by ~10% when all bodies are at rest?
That can be fixed (to some extent) by tweaking stiffness + relaxation + contactSkinSize of the contact materials. Reducing gravity also helps. Stacking problems are difficult to solve perfectly.
When contact stiffness is set to
Number.MAX_VALUE
in the circles demo, there often are a few circles that overlap quite a bit, even after they've all settled down. In the restitution demo I noticed that the circle on the left is occasionally drawn intersecting with the block below it.My hope is that these stiff objects might never overlap, overlap by very tiny amounts, or (at least) overlap for brief durations only.