# Stretchy Distance Constraint

Hi, I have a use case where I’m trying to make something like cloth simulation in havok. This is done by applying the movement of physics bodies with distance constraints to the vertices of a plane. The issue is the distance constraints are not behaving as expected, giving the cloth a stretchy / saggy look. To my understanding the distanceConstraint has a max distance, that in the example is set to the initial distance when the plane is straight. But the result is the plane actually sags. The more vertices and distance constraints, the saggier.

Maybe I am missing something, or maybe a different kind of constraint needs to be used?
The expected result is the plane is straight initially, and beginning to sag only when the outer edges would move inwards.

I think the sagging is caused by gravity in this case? As it would pull all the non-fixed bodies downwards

Gravity indeed pulls down the physics bodies that have mass. However in this case these bodies have distance constraints between them and the maximum distance between them is set on initialization time to be the distance when the cloth is straight. To me it seems there is an issue with the distance constraint max distance being exceeded when gravity is applied. If the amount of vertices and physics bodies increase, so does the sag. Maybe I am not understanding how the distance constraint works or the approach is not correct. Would be awesome to get someone who worked with distance constraints in Havok, but I don’t know who to tag.

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.