- Home /
ConfigurableJoint - angular positions (rotation) problem
I'm using ConfigurableJoints for a mechanical rig. Some some joints have 1 DOF (angular X), some joints have 2 DOF (angular X,Y) and some joints have 3 DOF (angular X,Y,Z). I switch between velocity mode and position mode - velocity mode when I'm moving the joint, and position mode when the joint is at the desired position. This works as should.
Problem is when rotating the joint beyond 90 degrees around any axis. I "measure" the actual position (rotation) of the joint by using:
(Quaternion.Inverse(_ConnectedRigidBody.rotation) * _JointRigidBody.rotation).eulerAngles
If I for example rotate the X-axis of the joint, the measured x-value is fine up to 90 degrees. When the rotation > 90, the x-value starts to decrease, ie 89, 88, 87, 86 ... Same goes for rotations down to -90 degress - they are fine. But below -90 degrees, the measured value changes direction, ie -89, -88, -87, -86 ...
I have tried different ways of measuring the angle. I have re-inported my meshes with corrected pivot points, I have made children to the rotating parts trying to measure their rotation ... and I always get the same result - measured rotation values are fine up to 90 degrees (or down to -90) and then they change "direction".
I'm guessing there is something about the conversion from Quaternion to euler angles that is the problem, but I know too little about such conversions to figure out how to fix this.
Any idea of what I'm missing out on? Any advice is appreciated.
Thanx in advance ///JmD
The problem is that there are several ways to build a facing out of x,y,z Euler angles, using different combinations of numbers. For example (which may be what you are getting) an x-rotation of 95 degrees can be made by rotating 85 degrees in x, then 180 around y.
If you actually need the angle on, say, the x-axis the common trick is to project to the yz-plane first.
Thank you for the tip, Owen! I guess that principle works for the other axes as well, ie, for the y-angle, project to the xz-plane first and for the z-angle project to the xy-plane first?
///JmD
The thing to be careful about is that the project-to-plane trick gives the world angle, only good for the direction of the "first" spin. Usually when you have x,y,z angles, you're thinking of a spin on the global y, but then the second spin on the new, local z, then on the even newer local x.
So, for combining it won't work (I think,) but for checking against maximums should be fine.
Answer by inum76 · Oct 07, 2015 at 01:17 AM
I found while using scrips, C#, The Rigidbody falls asleep. You need to wake it up within the script during each update. It is a bad idea to mess with a Quaternion directly. You should set XYZ in Euler angles with a vector3.
public Vector3 Vec1; Then you set your Quaternion with it, this way: private Quaternion QVec1; QVec1 = Quaternion.Euler (Vec1); QVec1 would be your set Quaternion with the angles you wish it to have. This is my vid on the subject you ask about, if you wish to check it out. Link: ConfigurableJointScript 1 Hope this helps.