Hey all,
I’ve noticed that the angle limits on Hinge Joint 2D are a bit weird.
Here’s a gif of it doing weird thing:
It’s a simple setup, just a rigidbody with hinge joint 2D with angle limits enabled.
The angle limits are setup as such:
min angle = -25
max angle = 25
It seems like at a certain point, the joint decided to rotate in the opposite way rather than going with the nearest angle. In my case, it does that when the parent object is horizontal and pointing to the left. It doesn’t do this when it’s pointing to the right.
I hope my explanation makes sense?
I’m using Unity 2019.4.3
In the gif above I’m using bones from 2D animation package, but I’ve tested without it, and it shows the same results.
Did I do something wrong?
Could this be a bug?
Anyone else encountered this?
Physics won’t work correctly if you’re modifying the Transform directly and this especially applies to joints. Modifying the Transform is simply instantly teleporting it to a new pose and joints start their calculations again.
The only thing that should move in physics is a Rigidbody2D.
Sorry to bump this,
But I’ve come across needing to do this again, and I’ve done some more tests.
My use case was: I needed to add physics that are attached to a part of an animated character.
The HingeJoint2D works fine if you are not using the angle limit, but when you do, the issue occured.
So the way I understand it, there’s no way to do this with physics 2D?
Because the character animation, well, they modify the Transform. Unless I’m missing something obvious, I don’t see a way to animate the RigidBody2D position directly?
So that led me to test a similar case using Physics 3D instead.
And it works as expected, even when modifying the Transfom.
So I guess I’ll just use 3D Physics instead.
But why they behave differently? This surely must count as bug, right?
At the beginning of my game, the object is placed in this way, but there is still a strange phenomenon of rotation. For example, I created two boxes (2D) a and B. the z-axis angle of a is 170, which is located on the right side, while the corner of B is D190. Place them on the right side, connect them with hingejoint, and set the limiting angle to (- 45, 45), which will still happen. I didn’t set the transform properties directly. But when I set the angle of B to 179, it’s OK. In other words, the z-axis angle cannot be greater than 180.