public void BreakIfNotClicked() { if (!WasClicked) { _joint.breakForce = 0; _joint.GetComponent <Rigidbody>().AddForce(Vector3.up * 50); } }
private void Spawn() { Clear(); int count = (int)(length / partDistance); Vector3 position; CharacterJoint temp = null; for (int i = 0; i < count; i++) { position = transform.position; position.y -= partDistance * (i + 1); temp = Instantiate(partPrefab, position, Quaternion.identity, parentObject.transform); temp.name = parentObject.transform.childCount.ToString(); m_parts.Add(temp.gameObject); if (i == 0) { if (snapFirst) { temp.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } Destroy(temp); } else { temp.connectedBody = parentObject.transform.Find((parentObject.transform.childCount - 1).ToString()).GetComponent <Rigidbody>(); } } if (snapLast) { parentObject.transform.Find(parentObject.transform.childCount.ToString()).GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } }
void BuildRope() { tubeRenderer = new GameObject("TubeRenderer_" + gameObject.name); line = tubeRenderer.AddComponent(typeof(TubeRenderer)) as TubeRenderer; line.useMeshCollision = useMeshCollision; // Find the amount of segments based on the distance and resolution // Example: [resolution of 1.0 = 1 joint per unit of distance] segments = Mathf.RoundToInt(Vector3.Distance(transform.position, target.position) * resolution); if (material) { material.SetTextureScale("_MainTex", new Vector2(1, segments + 2)); if (material.GetTexture("_BumpMap")) { material.SetTextureScale("_BumpMap", new Vector2(1, segments + 2)); } } line.vertices = new TubeVertex[segments]; line.crossSegments = radialSegments; line.material = material; segmentPos = new Vector3[segments]; joints = new GameObject[segments]; segmentPos[0] = transform.position; segmentPos[segments - 1] = target.position; // Find the distance between each segment int segs = segments - 1; Vector3 seperation = ((target.position - transform.position) / segs); for (int s = 0; s < segments; s++) { // Find the each segments position using the slope from above Vector3 vector = (seperation * s) + transform.position; segmentPos[s] = vector; //Add Physics to the segments AddJointPhysics(s); } // Attach the joints to the target object and parent it to this object CharacterJoint end = target.gameObject.AddComponent(typeof(CharacterJoint)) as CharacterJoint; end.connectedBody = joints[joints.Length - 1].transform.GetComponent <Rigidbody>(); end.swingAxis = swingAxis; SoftJointLimit sjl; sjl = end.lowTwistLimit; sjl.limit = lowTwistLimit; end.lowTwistLimit = sjl; sjl = end.highTwistLimit; sjl.limit = highTwistLimit; end.highTwistLimit = sjl; sjl = end.swing1Limit; sjl.limit = swing1Limit; end.swing1Limit = sjl; target.parent = transform; if (endRestrained) { end.GetComponent <Rigidbody>().isKinematic = true; } if (startRestrained) { transform.GetComponent <Rigidbody>().isKinematic = true; } // Rope = true, The rope now exists in the scene! rope = true; }
private void BuildRope() { tubeRenderer = new GameObject("TubeRenderer_" + gameObject.name); // присоединяем к GameObject класс, получаем ссылку на объект этого класса line = tubeRenderer.AddComponent <TubeRenderer2>(); // теперь line - экземпляр TubeRenderer2 line.useMeshCollision = useMeshCollision; // Find the amount of segments based on the distance and resolution // Example: [resolution of 1.0 = 1 joint per unit of distance] segments = Mathf.FloorToInt(Vector3.Distance(transform.position, target.position) * resolution); if (material != null) { material.SetTextureScale("_MainTex", new Vector2(1, segments + 2)); if (material.GetTexture("_BumpMap")) { material.SetTextureScale("_BumpMap", new Vector2(1, segments + 2)); } } line.vertices = new TubeVertex[segments]; line.crossSegments = radialSegments; line.material = material; segmentPos = new Vector3[segments]; joints = new GameObject[segments]; segmentPos[0] = transform.position; segmentPos[segments - 1] = target.position; // Find the distance between each segment int segs = segments - 1; Vector3 seperation = ((target.position - transform.position) / segs); for (int s = 0; s < segments; s++) { // Find the each segments position using the slope from above Vector3 vector = (seperation * s) + transform.position; segmentPos[s] = vector; //Add Physics to the segments AddJointPhysics(s); } // Attach the joints to the target object and parent it to this object CharacterJoint end = target.gameObject.AddComponent <CharacterJoint> (); end.connectedBody = joints[joints.Length - 1].transform.GetComponent <Rigidbody> (); end.swingAxis = swingAxis; SoftJointLimit limit1 = end.lowTwistLimit; limit1.limit = lowTwistLimit; end.lowTwistLimit = limit1; SoftJointLimit limit2 = end.highTwistLimit; limit2.limit = highTwistLimit; end.highTwistLimit = limit2; SoftJointLimit limit3 = end.swing1Limit; limit3.limit = swing1Limit; end.swing1Limit = limit3; target.parent = transform; if (endRestrained) { end.GetComponent <Rigidbody> ().isKinematic = true; } // FEDOR ***************** end.GetComponent <Rigidbody>().useGravity = gameObject.GetComponent <Rigidbody>().useGravity; // *********************** if (startRestrained) { transform.GetComponent <Rigidbody> ().isKinematic = true; } // Rope = true, The rope now exists in the scene! rope = true; }
public void BuildRopeJoints() { int newSegments = 0; int allSegments = (int)(Vector3.Distance(transform.position, target.position) * resolution); if (_segments == 0) { _segments = newSegments = allSegments; if (_segmentPos.Count < 1) { _segmentPos.Add(transform.position); _segmentPos.Add(target.position); } } else { newSegments = allSegments - _segments; _segments = allSegments; } while (newSegments < 0) { _segmentPos.RemoveAt(1); Destroy(_joints[1]); _joints.RemoveAt(1); _line.vertices = new TubeVertex[_segments]; newSegments++; } if (newSegments == 0) { if (target != null) { // Does rope exist? If so, update its position if (_rope) { _line.SetPoints(_segmentPos, ropeWidth, Color.white); _line.enabled = true; _segmentPos[0] = transform.position; for (int s = 1; s < _segments; s++) { _segmentPos[s] = _joints[s].transform.position; } } } return; } if (_tubeRenderer == null) { _tubeRenderer = new GameObject("TubeRenderer_" + gameObject.name); _line = _tubeRenderer.AddComponent <TubeRenderer>(); _line.useMeshCollision = useMeshCollision; if (material != null) { material.SetTextureScale("_MainTex", new Vector2(1, _segments + 2)); if (material.GetTexture("_BumpMap") != null) { material.SetTextureScale("_BumpMap", new Vector2(1, _segments + 2)); } } _line.crossSegments = radialSegments; _line.material = material; } _line.vertices = new TubeVertex[_segments]; _segmentPos.InsertRange(1, new Vector3[newSegments]); //Ensure start and end are correct _segmentPos[0] = transform.position; //probably unneeded _segmentPos[_segmentPos.Count - 1] = target.position; //joints something AddJointPhysics(0); //Add Joint to object this script is attached to. In this case probably the hook gun int segs = _segments - 1; Vector3 seperation = (target.position - transform.position) / segs; for (int n = 0; n < newSegments; n++) { _segmentPos[n + 1] = (seperation * (n + 1)) + transform.position; AddJointPhysics(n + 1); } //for (int i = 0; i < _segments; i++) //{ // //Set and update position of segments and update joints //} CharacterJoint end = target.gameObject.GetComponent <CharacterJoint>(); if (end == null) { end = target.gameObject.AddComponent <CharacterJoint>(); end.connectedBody = _joints[_joints.Count - 1].transform.GetComponent <Rigidbody>(); end.connectedBody.useGravity = false; end.swingAxis = swingAxis; end.lowTwistLimit = SetSoftJointLimitLimit(end.lowTwistLimit, lowTwistLimit); end.highTwistLimit = SetSoftJointLimitLimit(end.highTwistLimit, highTwistLimit); end.swing1Limit = SetSoftJointLimitLimit(end.swing1Limit, swing1Limit); } //target.parent = transform; if (endRestrained) { end.GetComponent <Rigidbody>().isKinematic = true; } if (startRestrained) { transform.GetComponent <Rigidbody>().isKinematic = true; } // Rope = true, The rope now exists in the scene! _rope = true; }
public void Start() { _targetRigidbody = TargetJoint.GetComponent <Rigidbody>(); }
private void BuildRope() { _tubeRenderer = new GameObject("TubeRenderer_" + gameObject.name); _line = _tubeRenderer.AddComponent <TubeRenderer>(); _line.useMeshCollision = useMeshCollision; // Find the amount of segments based on the distance and resolution // Example: [resolution of 1.0f = 1 joint per unit of distance] _segments = (int)(Vector3.Distance(transform.position, target.position) * resolution); if (material != null) { material.SetTextureScale("_MainTex", new Vector2(1, _segments + 2)); if (material.GetTexture("_BumpMap") != null) { material.SetTextureScale("_BumpMap", new Vector2(1, _segments + 2)); } } _line.vertices = new TubeVertex[_segments]; _line.crossSegments = radialSegments; _line.material = material; _segmentPos = new Vector3[_segments]; _joints = new GameObject[_segments]; _segmentPos[0] = transform.position; _segmentPos[_segments - 1] = target.position; // Find the distance between each segment int segs = _segments - 1; Vector3 seperation = (target.position - transform.position) / segs; for (int s = 0; s < _segments; s++) { // Find the each segments position using the slope from above Vector3 vector = (seperation * s) + transform.position; _segmentPos[s] = vector; if (s == 0) { _segmentPos[s] = transform.position; } if (s == segs) { _segmentPos[s] = target.position; } //Add Physics to the segments AddJointPhysics(s); } // Attach the joints to the target object and parent it to this object CharacterJoint end = target.gameObject.AddComponent <CharacterJoint>(); end.connectedBody = _joints[_joints.Length - 1].transform.GetComponent <Rigidbody>(); end.connectedBody.useGravity = false; end.swingAxis = swingAxis; //end.lowTwistLimit.limit = lowTwistLimit; //end.highTwistLimit.limit = highTwistLimit; //end.swing1Limit.limit = swing1Limit; end.lowTwistLimit = SetSoftJointLimitLimit(end.lowTwistLimit, lowTwistLimit); end.highTwistLimit = SetSoftJointLimitLimit(end.highTwistLimit, highTwistLimit); end.swing1Limit = SetSoftJointLimitLimit(end.swing1Limit, swing1Limit); //target.parent = transform; if (endRestrained) { end.GetComponent <Rigidbody>().isKinematic = true; } if (startRestrained) { transform.GetComponent <Rigidbody>().isKinematic = true; } // Rope = true, The rope now exists in the scene! _rope = true; }