public void AttachToRope() { if (rope_in_background != null && can_climb_rope) { if (is_climbing_rope) { DetachFromRope(false); } attached_rope = rope_in_background.rope; attached_rope.players_on_rope.Add(this); is_climbing_rope = true; rope_links = rope_in_background.GetComponent <Link>().all_segments; // Get the total length of this rope max_hooking_distance = rope_links.Count * rope_in_background.GetComponent <CircleCollider2D>().radius * 2; // Radius is half a circle. We need the diameter // Activate the springjoint on this object, and set the distance spring = rope_links[0].GetComponent <SpringJoint2D>(); spring.enabled = true; spring.connectedBody = m_Rigidbody2D; cur_distance = Vector2.Distance(this.transform.position, spring.gameObject.transform.position); spring.distance = cur_distance; this.m_AirControl = false; } }
public void AttachToRope(Link rope_object) { rope_in_background = rope_object; can_climb_rope = true; attached_rope = rope_object.rope; AttachToRope(); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Rope" && other.gameObject.GetComponentInParent <Link>().rope != this_rope && !this_rigidbody.isKinematic) { Debug.Log("Connecting ropes"); other.gameObject.name = "RopePiece"; GameObject.Destroy(this_link.GetComponent <AttachToTerrain>()); // Connect this rope to the rope that collided with us Link other_link = other.GetComponentInParent <Link>(); other_link.GetComponent <HingeJoint2D>().connectedBody = this_link.GetComponent <Rigidbody2D>(); other_link.GetComponent <HingeJoint2D>().enabled = true; RopeGenerator new_rope = other_link.rope; // Go through all the links, setting the new information // Link cur_link = other_link.all_segments[0].GetComponent<Link>(); other_link.all_segments.AddRange(this_link.all_segments); List <GameObject> new_all_links = other_link.all_segments; Debug.Log(new_all_links.Count); //while (cur_link != null) for (int x = 0; x < new_all_links.Count; x++) { Link cur_link = new_all_links[x].GetComponent <Link>(); cur_link.position_from_top_in_rope = x; cur_link.position_from_bottom_in_rope = new_all_links.Count - x; cur_link.all_segments = new_all_links; cur_link.top_most = new_all_links[0]; cur_link.bottom_most = new_all_links[new_all_links.Count - 1]; cur_link.transform.parent = new_rope.transform; cur_link.rope = new_rope; if (x > 0) { cur_link.below = new_all_links[x - 1]; } if (x < new_all_links.Count - 1) { cur_link.above = new_all_links[x + 1]; } //cur_link = cur_link.below.GetComponent<Link>(); //pos++; } new_rope.number_of_segments = new_all_links.Count; // Remove this from the rope list, add the combined rope again to the rope list ObjectManager.object_manager.RemoveRope(this_rope.gameObject); ObjectManager.object_manager.AddRope(new_rope.gameObject); //GameObject.Destroy(other_link.top_most.GetComponentInChildren<RopeCombiner>().gameObject); GameObject.Destroy(other.gameObject); GameObject.Destroy(this.gameObject); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); RopeGenerator myScript = (RopeGenerator)target; //if (GUILayout.Button("Generate Rope")) //{ // myScript.generate(); //} }
private void ApplayParams(RopeGenerator tmpRope) { tmpRope.ColliderRadius = _colliderRadius; tmpRope.Length = _length; tmpRope.MassOfBone = _massOfBone; tmpRope.BoneCount = _boneCount; tmpRope.JointAngleLimit = _jointAngleLimit; tmpRope.RotateAngleLimit = _rotateAngleLimit; tmpRope.AngularDriveSpringStart = _angularDriveSpringStart; tmpRope.AngularDriveSpringStop = _angularDriveSpringStop; tmpRope.RestrictFirstBone = _restrictFirstBone; }
private GameObject[] MakeRope(GameObject go, float length) { var meshGenerator = new RopeMeshCylinderGenerator(); var material = new Material(Shader.Find("Diffuse")); var tmpRope = new RopeGenerator(meshGenerator, material, go); tmpRope.Length = length; tmpRope.BoneCount = Math.Max((int)length, 2); return(tmpRope.MakeOne()); }
private void Start() { isHoldingNumber = 999; //Just for check true without bool thisRigidBody = GetComponent <Rigidbody2D>(); holdingRigidBody = thisRigidBody; _ropeGenerator = GameObject.Find("RopeGenerator").GetComponent <RopeGenerator>(); cameraXDis = Camera.main.orthographicSize / 9 * 16; _playerAnimations = transform.Find("PlayerSprite").GetComponent <PlayerAnimations>(); _gameController = GameObject.Find("GameController").GetComponent <GameController>(); thisRigidBody.velocity += Vector2.right * initialVelocity; canvasInGame = GameObject.Find("CanvasInGame"); _gameVars = GameObject.Find("GameController").GetComponent <GameVars>(); initVelocityMod = velocityMod; _soundEmmiter = Camera.main.transform.Find("Sounds").GetComponent <SoundEmmiter>(); }
private void MakeRope() { if (_meshGenerator == null) { Debug.LogError("MeshGenerator is not specified"); return; } var go = new GameObject("New Rope (" + (++_genCounter).ToString() + ")"); go.transform.localPosition = new Vector3(0, 0, 0); go.transform.rotation = Quaternion.FromToRotation(Vector3.right, Vector3.down); if (_parrent != null) { go.transform.parent = _parrent.transform; } var tmpRope = new RopeGenerator(_meshGenerator, go); ApplayParams(tmpRope); var result = tmpRope.MakeOne(); if (_optimizeMesh) { MeshUtility.Optimize(result.Mesh); } if (_saveMesh) { var path = EditorUtility.SaveFilePanel( "Save mesh", "", "new_mesh.asset", "asset"); path = FileUtil.GetProjectRelativePath(path); if (path.Length != 0) { AssetDatabase.CreateAsset(result.Mesh, path); AssetDatabase.SaveAssets(); } } }
public void AttachToRope() { if (rope_in_background != null && can_climb_rope) { if (is_climbing_rope) DetachFromRope(false); attached_rope = rope_in_background.rope; attached_rope.players_on_rope.Add(this); is_climbing_rope = true; rope_links = rope_in_background.GetComponent<Link>().all_segments; // Get the total length of this rope max_hooking_distance = rope_links.Count * rope_in_background.GetComponent<CircleCollider2D>().radius * 2; // Radius is half a circle. We need the diameter // Activate the springjoint on this object, and set the distance spring = rope_links[0].GetComponent<SpringJoint2D>(); spring.enabled = true; spring.connectedBody = m_Rigidbody2D; cur_distance = Vector2.Distance(this.transform.position, spring.gameObject.transform.position); spring.distance = cur_distance; this.m_AirControl = false; } }
void Start() { this_link = this.GetComponentInParent <Link>(); this_rope = this_link.rope; this_rigidbody = this_link.GetComponent <Rigidbody2D>(); }