I'm trying to implement 2D JointLimits.

I already implemented an Angle joint that constrains two bodies to remain at some fixed angle. For this I used the equations:

difference = (_body2.TotalRotation - _body1.TotalRotation) - targetAngle;

_bias = -_biasFactor * inverseDt * difference;

All is good with this joint.

For the joint limit constraint, I'd like to provide and Lower Limit and an Upper Limit and constrain the angle between 2 bodies to remain between these 2 angles.

Should I just implement this as 2 in equality constraints, one for each limit, all within a single LimitedAngleJoint class

I'd also need to allow for slop, similar to the contact constraints.

Anything else I need to take into consideration?

For reference, here is the key code from my regular AngleJoint:

Code: Select all

```
public override void PreStep(float inverseDt) {
float difference;
difference = (_body2.TotalRotation - _body1.TotalRotation) - _targetAngle;
_bias = -_biasFactor * inverseDt * difference;
_accumulatedAngularImpulse *= _relaxation;
_body1.AngularVelocity -= _body1.InverseMomentOfInertia * _accumulatedAngularImpulse;
_body2.AngularVelocity += _body2.InverseMomentOfInertia * _accumulatedAngularImpulse;
}
public override void Update() {
float angularImpulse;
angularImpulse = (_bias - _body2.AngularVelocity + _body1.AngularVelocity) / (_body1.InverseMomentOfInertia + _body2.InverseMomentOfInertia);
_accumulatedAngularImpulse += angularImpulse;
_body1.AngularVelocity -= _body1.InverseMomentOfInertia * angularImpulse;
_body2.AngularVelocity += _body2.InverseMomentOfInertia * angularImpulse;
}
```