I am having problems computing the targetrotation of a configurable joint.
START EDIT You can find the application resulting from this question here
background: I am swapping the JointDriveMode from velocity to position drive when the targetAngularVelocity magnitude is 0. So I need to compute out of the blue the targetRotation of a joint. I do not know nor can maintain a variable holding this variable since it was driven using velocity and the joint unfortunatly can not be queried for this. Also, the joint is not configured in worldspace.
for convenience and to avoid misinterpretations, I have added the sources of this specific problem online and with a webplayer version:
I am using currently:
This is not working when the rigidbody implementing the joint is itself constraint by another configurable joint. Basically it doesn't work with a chain of joints. it jumps to weird angles instead. While this works very well when the rigidbody holding the joint is not attached to anything. I could be wrong in this assumption, but that's what I am experiencing so far.
Is there actually a way to switch JointDriveMode from velocity to position and have the joint stay in its current position? Currently if you switch it jumps back to the default values.
Is there a proper way to find out about the targetRotation accuratly in all situations?
Thanks for your help. I can provide a small example if someone is interested to get a proper working case of this.
Ok, found the solution.
The solution that I implemented is to compute the position from the "parent" space which is the rigid body implementing the joint, then use lookRotation, the resulting quaternion is properly define in the local space.
One could probably do that directly with rotation component, if there is a better way I am all hears.
Interesting question. The only thing that strikes me is that you shouldn't have to go via euler angles. Just set the target rotation to transform.localRotation.
Anyway, not sure if that solves the problem. Probably not.
answered Aug 11 '10 at 01:16 PM
I've created a set of extension methods for computing a ConfigurableJoint's targetRotation from either a local or world rotation. The solution is not trivial, and all solutions I've found online have failed to take into account arbitrary "axis" and "secondary axis" values. With some careful quaternion math it's possible to transform a local or world space rotation into a joint space rotation while supporting variable joint axes.
answered Feb 15 at 07:03 AM