- Home /
Question by
Aria-Lliane · Feb 26, 2013 at 06:43 PM ·
rotationanglejoint
How to get a Joint's current Rotation/angle?
Hello, i know so far how to make a ConfigurableJoint move to target Rotation:
public void moveConfJoint (ConfigurableJoint joint, Quaternion rotation)
{
joint.targetRotation=rotation;
JointDrive drive= new JointDrive();
drive.positionSpring = 150;
drive.mode = JointDriveMode.Position;
drive.maximumForce=4;
joint.angularXDrive = drive;
joint.angularYZDrive = drive;
}
but with time it will also move with physics, so at a certain point id like to get its current Rotation, something like " Quaternion q = joint.getCurrentRotation; " or something like that, so i can get it's current state/Rotation, how can i do this? i know that HingeJoints have the "joint.angle" attribute, so what is the equivalent for Configurable Joints?
Comment
I've been thinking and I'd like to know what you guys think about this:
public Quaternion getJointRotation(ConfigurableJoint joint)
{
Quaternion q1=joint.connectedBody.rotation;
Quaternion q2=joint.gameObject.transform.rotation;
return(Quaternion.FromToRotation(q2.eulerAngles, q1.eulerAngles));
}
Best Answer
Answer by Aria-Lliane · Apr 13, 2013 at 05:12 PM
public Quaternion getJointRotation(ConfigurableJoint joint)
{
return(Quaternion.FromToRotation(joint.axis, joint.connectedBody.transform.rotation.eulerAngles));
}