Stretchy Distance Constraint

Like many physics engines, for speed, Havok uses an iterative constraint solver. One of the downsides of using a local solver is that there’s going to be some error remaining in the constraints. If you’re interested, Erin Catto has a good presentation about this at [1] - relevant section is from slide 18 onwards, but probably the most revealing slide for this kind of scenario is “Tall stacks are challenging too” on slide 32. The presentation is talking about contact constraints, but the ideas are the same for any constraint.

There’s a couple of different ways to reduce this error, you could try a combination of some of these:

  • Stepping the physics engine at a higher frequency (with lower deltaTime) will make the solver stiffer, as we get more time for the results to converge
  • Modify the masses of the bodies, so that the further away a body is from an “anchor,” the lighter that body is. This means that a body that’s further away from an anchor will moved more “easily” by the solver, and have less of a pulling effect on a body that’s closer to the anchor.
  • In addition to the distance constraint to a body’s neighbours, add an additional distance constraint between each body and it’s nearest anchor. This will add an additional constraint to help convergence when a body is far away from the anchor.

[1] https://box2d.org/files/ErinCatto_UnderstandingConstraints_GDC2014.pdf