- Home /
hingeJoint.angle equivalent for ConfigurableJoint?
I believe title is self explanatory.
how would ConfigurableJoint's equivalent for HingeJoint.angle look like?
Answer by UnitedBluff · Jul 13, 2015 at 10:02 AM
I came up with this and it seems to work. For some reason, in Jareikos function, secondary and third axes were switched, so my simple solution was simply to switch them again. On a sidenote: why are these functions not build in ? How can anyone make gameplay without reading values ? Anyway here is the function. The values returned in the Vector3 are between -180 and 180.
public float to180(float v) {
if (v > 180) {
v = v - 360;
}
return v;
}
Vector3 jointRotation(ConfigurableJoint joint)
{
Quaternion jointBasis = Quaternion.LookRotation(joint.secondaryAxis, Vector3.Cross(joint.axis, joint.secondaryAxis));
Quaternion jointBasisInverse = Quaternion.Inverse(jointBasis);
var rotation = (jointBasisInverse * Quaternion.Inverse(joint.connectedBody.rotation) * joint.GetComponent<Rigidbody>().transform.rotation * jointBasis).eulerAngles;
return new Vector3(to180(rotation.x), to180(rotation.z),to180(rotation.y));
}
Answer by Jean-Fabre · Nov 18, 2010 at 12:00 PM
Hi,
Assuming you want to rotate around x axis:
-- select the connected rigid body
-- lock every axes BUT angular X motion ( Angular XMotion should be set to #free, the rest to #lock)
-- set the angular Xdrive mode to "velocity"
-- set the angular Xdrive position spring to 0 ( we don't need this for velocity drive)
-- set the angular Xdrive position damper to 10 ( varies depending on weight and volumes of RB)
-- set the angular Xdrive position force to 20 ( varies depending on weight and volumes of RB)
Generally I set the damper value to half of the the position force. that might be wrong, but that works so far.
then as the thing is playing, change the target velocity X value to 1, or 2, maybe more, the joint will turn, set back to 0 to stop rotating the joint.
A very important settings when you want to do accurate joints.
-- modify the anchor value to define where the pivot point reference is ( leave as is for no
for a complete rig using just configurable joint set up as hinges:
http://forum.unity3d.com/threads/66871-Excavator-simulation
Hope it helps,
Jean
Answer by jareiko · Jul 17, 2013 at 10:30 PM
This isn't quite right yet but I think I have the beginnings of a solution:
Quaternion jointRotation(ConfigurableJoint joint) {
Quaternion jointBasis = Quaternion.LookRotation(joint.secondaryAxis, Vector3.Cross(joint.axis, joint.secondaryAxis));
Quaternion jointBasisInverse = Quaternion.Inverse(jointBasis);
return jointBasisInverse * Quaternion.Inverse(joint.connectedBody.rotation) * joint.rigidbody.rotation * jointBasis;
}
You can then use the .eulerAngles property to get the angles. The X component corresponds to the primary joint axis. Hopefully, Y and Z will correspond to secondaryAxis and the implicit third axis, but I haven't checked that these are correct yet. If they're not correct, the jointBasis calculation may need to be tweaked.
Eg:
float angle = jointRotation(joint).eulerAngles.x;
Answer by inum76 · Oct 07, 2015 at 01:16 AM
I found while using scrips, C#, The Rigidbody falls asleep. You need to wake it up within the script during each update. This is my vid on the subject if you wish to check it out. Link: ConfigurableJointScript 1 Hope this helps.
Your answer
Follow this Question
Related Questions
How do I set up a ConfigurableJoint so that it behaves just like a HingeJoint? 1 Answer
Help with Hinge and steering wheels 0 Answers
When add joints to wheelcollider then it is not collide with other collider 0 Answers
Sloppy HingeJoints 0 Answers
Hinge Joint with no displacement, strict rotation limits 1 Answer