public void setBodySpringStuff(CWRigidBody body, float spring, float damper, bool isFirst = true) { if (isFirst && body.getParentJoint() != null) { //Debug.Log(" ===== body === "+body.getParentJoint().jName); body.getParentJoint().setSpring(spring); body.getParentJoint().setDamper(damper); if (body.name.Contains("LowerArm") || body.name.Contains("LowerLeg")) { body.getParentJoint().getParent().getParentJoint().setSpring(spring); body.getParentJoint().getParent().getParentJoint().setDamper(damper); } } int count = body.getChildJointCount(); for (int i = 0; i < count; i++) { CWJoint joint = body.getChildJoint(i); joint.setSpring(spring); joint.setDamper(damper); //Debug.Log(" ===== child body === "+joint.jName); if (joint.getChild().getChildJointCount() > 0) { setBodySpringStuff(joint.getChild(), spring, damper, false); } } }
/** * This method is used to get the relative angular velocities of the parent and child bodies of joint i, * expressed in parent's local coordinates. * We'll assume that i is in the range 0 - joints.size()-1!!! */ public Vector3 getRelativeAngularVelocity(int i) { CWJoint joint = this.joints[i] as CWJoint; Quaternion parentOri = joint.getParent().getOrientation(); return(Quaternion.Inverse(parentOri) * (joint.getChild().getAngularVelocity() - joint.getParent().getAngularVelocity())); }
/** * This method is used to populate the relative orientation of the parent and child bodies of joint i. */ public Quaternion getRelativeOrientation(int i) { CWJoint joint = this.joints[i] as CWJoint; Quaternion parentOri = joint.getParent().getOrientation(); Quaternion childOri = joint.getChild().getOrientation(); return(Quaternion.Inverse(parentOri) * childOri); }