# Hinge Joint 2D breaking?

Hello.

Me and my brother recently started programming in Unity. We went from Java/lwjgl to Unity, with the idea to create a topdown rpg. At first, we made animations; but then we figured we could make it entirely physics based.
To do this, we needed to emulate at least arms and joints, and thought we could use Hinge Joint 2D.

However, after attaching a sword to our character using a HingeJoint2D, the joint seems to break every now and then. If we move or rotate, it sometimes skips the angle limit. This results in the sword spinning half a turn.
It seems that when we rotate our character, the joint doesn’t update in time; is this the case? And how can we fix it?

Festum.

Make sure that the way you are moving the joint is by setting values for the motor.

Thanks Kurius, though we are not moving the joint.

Further testing to minimize the possibilities for bugs, made me arrive at the following scenario.

Setup:
Gravity and drag is set to zero.
Rigidbody2D A containing a HingeJoint2D, connecting a RigidBody2D B.
The HingeJoint2D has limits set to 0 and 90 degrees. (No motor involved)

Problem:
When A rotates B will not rotate, until it’s rotation reaches one of the limits - that’s what we want.
Occasionally, though - the rotation of B exceeds the limit, and starts a self-propelled rotation towards the other limit.
(In certain setups this rotation haven’t stopped at the next limit, but kept rotating till A was rotated into seemingly unrelated angels.)

How could we make sure that the rotation never exceeds the limit given the joint?
If that’s not possible - What kind of joints (or technique) could we use for a physics driven 2D (top-down) sword swing?

Any help would be much appreciated.

• Gomric

Well an abstract workaround would be to shape the colliders of each rigid body such that angle limits are enforced via the colliders hitting each other rather than relying on the limits of the hinge joint itself.

As an aside, I believe that the limits of the hinge joint expect the motor to be activated, thus the motor obeys the limits, rather than the physics world obeying the limits. Unfortunately it sounds like the needs of your game don’t lend themselves to having the motor activated.

Anyway, if you want a crude drawing of what I’m talking about in the workaround, just let me know.

Thanks again, Kurius.
We tried making a “socket” for our arm, but even then it disjointed (literally).

What seem to work is a block, blocking the center of mass, effectively enforcing the limits.
We’ll try to make that block only collide with the block which we try to put angular limits on.

I’ll give an update when this is thoroughly tested.

looks like it never came a update

Note that you’re replying to a post from 2014 but what you’re saying isn’t clear. There’s been a huge amounts of updates to the physics system over the years, including the HingeJoint2D but of course, you don’t specify what issue you’re having so it’s impossible to know.

The HingeJoint2D now will not exceed its limits under any circumstance.