HingeJoint2D Angle Limits Issue

I have a chain of objects connected with HingeJoint2Ds that use angle limits. If you squeeze the chain between two pieces of collision the right way, the chain of joints can get mangled in a weird orientation (usually it’s one joint) that is outside the angle limit. If I disable the angle limits now, the chain returns to the normal orientation (because of gravity), but then if I re-enable the limits, it returns to the mangled orientation. This seems like a bug because re-enabling the angle limits forces the joint outside the angle limits. And the joints getting mangled in the weird orientation feels like a bug, because the joint should be able to resolve it on it’s own anyway. Is there some way to work around this issue?

It’s not a bug, the solver can only do so much given the iterations you allow in the settings etc and often it’s in a situation where there is no “good” solution i.e. cases where multiple contacts forces something out of constraint.

There are many instances where complex joint chains “explode” or go out of constraint. Disable/Enabling constraints (such as rotation) means it’s resetting the cached state that “exploded” in the first place but it’s also removing constraints so in some circumstances the solver can return to a better state.

  • Ensure you don’t have large mass-ratios
  • Ensure there is a solution the solver can get to
  • Increase the number of iterations you’re allowing the solver to use
  • Increase the frequency of the simulation steps

Take a quick look at this example in my PhysicsExamples2D GitHub repo. Maybe there’s something there that might help.

https://www.youtube.com/watch?v=EH9nj3zcfFQ

I mean it’s fine if it can’t solve it while the multiple contacts are preventing it, but after there is no contacts touching the chain anymore, shouldn’t it be able to solve it then? It almost feels like the solver gives up as soon as it encounters a state it can’t solve and takes the current “unsolved” state as the new “default” where the rotation limits are applied to. This is the reason it feels like a bug, because it can’t return to the intended constraints after failing to solve them earlier.

Also, I can’t view the embedded video. Can you add a normal link to it?

Not if the joints have “exploded”. The term explode here means it can end up in chaos because the forces have grown to huge proportions and joints that get into this state don’t magically return to some known state. This is pure Box2D, there is no “fixing” this and you can create this kind of thing in most engines supporting constraints. It’s not a logical reasoning solver, it’s math all the way down so resetting them is the only way. :slight_smile:

I would ask though that you respond regarding the items I listed about avoiding this. Maybe confirming whether you’re simply using the default solver iterations etc.

Right now it’s hard to say anything more without seeing it in action though so maybe you can upload a quick video showing the problem.

It’s a public youtube link which I’ve shared many times:

https://youtu.be/ZgsrAHGU-mA?si=4weqHxJXAVvsccC2