/// <summary> /// Connects the gameobject to the starting end endingJoint /// </summary> public void ConnectToJoints() { if (startingJoint == null || endingJoint == null) { return; } startingJoint.Connect(this); endingJoint.Connect(this); // connect the musclejoints with a spring joint spring = startingJoint.gameObject.AddComponent <SpringJoint>(); spring.spring = SPRING_STRENGTH; spring.damper = 50; spring.minDistance = 0; spring.maxDistance = 0; //spring.autoConfigureConnectedAnchor = true; spring.anchor = startingJoint.position; spring.connectedAnchor = endingJoint.position; spring.connectedBody = endingJoint.GetComponent <Rigidbody>(); spring.enablePreprocessing = true; spring.enableCollision = false; // break forces //spring.breakForce = 5000; //spring.breakTorque = 5000; }
public static IList <MuscleJoint> CopyHierarchy(IList <MuscleJoint> joints) { IList <MuscleJoint> mirrorJoints = new MuscleJoint[joints.Count]; for (int i = 0; i < joints.Count; i++) { MuscleJoint originalJoint = joints[i]; Transform mirrorTransform = new GameObject(joints[i].name + "_IK").transform; mirrorTransform.position = originalJoint.transform.position; mirrorTransform.rotation = originalJoint.transform.rotation; MuscleJoint mirrorJoint = mirrorTransform.gameObject.AddComponent <MuscleJoint>(); mirrorJoint.Initialize(originalJoint); GameObject.Destroy(mirrorJoint.GetComponent <SphereCollider>()); // Todo: superhacky if (i > 0) { mirrorTransform.parent = mirrorJoints[i - 1].transform; } mirrorJoints[i] = mirrorJoint; } return(mirrorJoints); }
/** Applies the starting Force to the startingJoint and endingForce to the endingJoint. force specifies the magnitude of the force. */ private void ApplyForces(float force, Vector3 startingForce, Vector3 endingForce) { Vector3 scaleVector = new Vector3(force, force, force); endingForce.Scale(scaleVector); startingForce.Scale(scaleVector); Assert.IsFalse(float.IsNaN(endingForce.x), "force: " + force); Assert.IsFalse(float.IsNaN(startingForce.x), "force: " + force); startingJoint.GetComponent <FixedJoint>().connectedBody.AddForceAtPosition(startingForce, startingJoint.position); endingJoint.GetComponent <FixedJoint>().connectedBody.AddForceAtPosition(endingForce, endingJoint.position); }