DistanceConstraint constructor
distance
The distance to keep. If undefined, it will be set to the current distance between bodyA and bodyB.
maxForce
The maximum force that should be applied to constrain the bodies.
Implementation
DistanceConstraint(Body bodyA, Body bodyB, [double? distance, double maxForce = 1e6]):super(bodyA, bodyB) {
this.distance = distance ?? bodyA.position.distanceTo(bodyB.position);
distanceEquation = ContactEquation(bodyA, bodyB);
final eq = distanceEquation;
equations.add(eq);
// Make it bidirectional
eq.minForce = -maxForce;
eq.maxForce = maxForce;
}