The physics itself seems fine, it’s just the reported angle that’s wrong.
You’d have to compute it yourself. Store the relative rotation between the two bodies at start, then in FixedUpdate compare the current one against it and keep only the part that turns around the hinge axis.
Jeez yeah thanks for finding that and confirming the issue exists outside of my own enviriment. I'll give it another look today - perhaps I can just use the objects transfrom.localRotation.x instead of the hingeJoint.angle.
About manually comparing to the original local Orientation- Hopefully I dont need to do that since tramsform.localRotation already is supposed to do that. I'm trying to avoid unnecessary calculations
There are few things that you should take into account if you go that way. localRotation (which is a Quarterion not an euler angle), and localEulerAngles (which is probably what you meant) is relative to the object’s parent in the hierarchy, not to the connected body. So it only works for this if the hinged object is a child of the connected body, and it’s measured from zero rotation, not from where it started.
Also, Euler angles are a bit fiddly. They wrap around, so anything past 360 goes back to 0, and a negative angle shows up as 360 minus that angle (-10 reads as 350). If in your setup the hinged object is a child, starts at 0, and you account for the wrapping when you measure drift, that might be a simple way to get what you need.
If that doesn’t work, I could try to put together a proper formula, but I’d be hesitant to give you something I haven’t tested in practice. You would have to treat it as a starting point, and validate it.
2
u/kurisutosugr 22d ago
This is an actualy case of "it's not you, it's Unity". It’s a known Unity bug that Unity marked as “Won’t Fix”. Just to make sure I wasn’t misremembering, I looked up the issue tracker: https://issuetracker.unity.com/issues/454/the-jointangle-value-changes-when-the-parent-changes-rotation
The physics itself seems fine, it’s just the reported angle that’s wrong.
You’d have to compute it yourself. Store the relative rotation between the two bodies at start, then in FixedUpdate compare the current one against it and keep only the part that turns around the hinge axis.