- Home /
hinge.angle returns wrong angle
While trying to use Unity as a simulation environment for robotics, I've come across a pretty serious bug. In order for me to control a robot arm in my scene, I need to have access to the angles from HingeJoints. However, when I use
hinge = GetComponent<HingeJoint>();
angle = hinge.angle;
hinge.angle does not always provide the actual angle between a HingeJoint rigidbody and the connected rigidbody. The angle returned seems to be dependent on the global orientation of the connected rigidbodies, in addition to their relative orientation.
As an example I've included a link here to a package that contains a scene called test_scene with a 6 DoF robot arm I made as an example. The arm has springs in most of its joints to stop it from completely flopping around, and has some scripts attached to report the angle I calculate and the error between it and hinge.angle. You can see the steady state orientation of the arm and the scripts below.
The HingeJoint connecting the shoulder to the base is told to rotate at constant velocity, meaning the shoulder HingeJoint should be the only one with a changing angle. If you play the scene and look at the shoulder GameObject under the hinge_angle_tester, you'll see the errorAngle is approximately zero as the arm rotates around. Looking at arm_1 however, shows that errorAngle is changing continuously as the arm rotates, and can be as large as 180 degrees.
This is not only a problem because it forces me to manually calculate hinge angle/velocities, but it also results in hinge damping providing unrealistic torques since Unity thinks the angle is changing when it isn't. If I wanted to I could also calculate my own damping, but I also need to be able to set limits for my HingeJoints, which I see as being an even more annoying can of worms to deal with.
I've seen this issue raised before in this Unity forum back in 2016, and it is obviously still a problem. I hope that someone can shed some light on why this problem exists, or confirm that it will eventually be fixed. Please let me know if there is anything else I should provide, and I have submitted a bug report.
My System
Windows 10 running Unity 2019.4.7f1
Your answer
Follow this Question
Related Questions
HingeJoint has a little bug? 0 Answers
Why are my hinge joints inaccurate? 1 Answer
OnTriggerEnter fired incorrectly (android device only) 0 Answers
reproducing hingejoint.angle 0 Answers
Ads dashboard website keep refreshing? 0 Answers