private void Awake() { var joints = transform.GetComponentsInChildren <ConfigurableJoint>(); foreach (var joint in joints) { Joint.CreateComponent(joint, JointForcePower); } var rigidbodies = transform.GetComponentsInChildren <Rigidbody>(); foreach (var rigidbody in rigidbodies) { rigidbody.solverIterations = 30; } }
private void Connect(int connectorId, BodyComponent otherComponent) { Assert.IsTrue(connectorId < _masterConnectors.Length); var connector = EnableConnector(connectorId); otherComponent.EnableSlaveConnector(); var rot = connector.transform.rotation * Quaternion.Inverse(otherComponent ._slaveConnector.transform.rotation); otherComponent.CentralBody.transform.rotation = rot * otherComponent.CentralBody.transform.rotation; var diff = (connector.transform.position - otherComponent._slaveConnector.transform.position); otherComponent.CentralBody.transform.position += diff; otherComponent.ToRigid(); var joint = otherComponent.CentralBody.gameObject.AddComponent <ConfigurableJoint>(); // joint.lowAngularXLimit = new SoftJointLimit {limit = -60}; // joint.highAngularXLimit = new SoftJointLimit {limit = 60}; // joint.angularYLimit = new SoftJointLimit {limit = 60}; // joint.angularZLimit = new SoftJointLimit {limit = 60}; joint.lowAngularXLimit = new SoftJointLimit { limit = -60 }; joint.highAngularXLimit = new SoftJointLimit { limit = 60 }; joint.angularYLimit = new SoftJointLimit { limit = 30 }; joint.angularZLimit = new SoftJointLimit { limit = 0 }; joint.projectionMode = JointProjectionMode.PositionAndRotation; // 爆発防止 joint.connectedBody = CentralBody.GetComponent <Rigidbody>(); joint.anchor = otherComponent._slaveConnector.transform.localPosition; Joint.CreateComponent(joint, targetForce: _targetForce); Physics.IgnoreCollision(CentralBody.GetComponent <Collider>(), otherComponent.CentralBody.GetComponent <Collider>()); connector.available = false; connector.ConnectedComponent = otherComponent; }