void Update() { if (isRopeAttached) { if (colideObject == null) { collisionType = RopeCollisionType.NONE; stopRope(); } if (collisionType == RopeCollisionType.CAN_ATTACH) { getRopePullForce(curLength, player.GetComponent <HingeJoint2D> (), this.gameObject, player.gameObject, 200); } if (collisionType == RopeCollisionType.CAN_ATTACH_AND_DROP) { float length = (transform.position - colideObject.transform.position).magnitude; getRopePullForce(curLength, player.GetComponent <HingeJoint2D> (), colideObject, player.gameObject, length * 50); getRopePullForce(curLength, null, player.gameObject, colideObject, length * 7); } } if (isRopeLaunched) { lineRenderer.SetPosition(0, transform.position + new Vector3(0, 0, 1)); lineRenderer.SetPosition(1, player.transform.position + new Vector3(0, 0, 1)); // Rope fly if (!isRopeAttached) { rigidBody2D.velocity = moveVector; } } }
void Awake() { enabled = false; isRopeLaunched = false; isRopeAttached = false; rigidBody2D = GetComponent <Rigidbody2D> (); lineRenderer = GetComponent <LineRenderer> (); colideObject = null; collisionType = RopeCollisionType.NONE; Debug.Log("Rope Start!"); }
void OnCollisionEnter2D(Collision2D collision) { Collider2D other = collision.collider; if (other.GetComponent <Collision> () != null && isRopeLaunched) { RopeCollisionType col = other.GetComponent <Collision> ().collideWithRopeHead(this); switch (col) { case RopeCollisionType.CAN_ATTACH: colideObject = other.gameObject; moveVector = new Vector2(0, 0); transform.parent = other.transform; rigidBody2D.isKinematic = true; GetComponent <CircleCollider2D> ().isTrigger = true; isRopeAttached = true; Instantiate(Resources.Load("Prefabs/RopeAttachedParticle"), transform.position, new Quaternion()); collisionType = RopeCollisionType.CAN_ATTACH; break; case RopeCollisionType.CAN_ATTACH_AND_DROP: colideObject = other.gameObject; moveVector = new Vector2(0, 0); transform.parent = other.transform; rigidBody2D.isKinematic = true; GetComponent <CircleCollider2D> ().isTrigger = true; isRopeAttached = true; Instantiate(Resources.Load("Prefabs/RopeAttachedParticle"), transform.position, new Quaternion()); collisionType = RopeCollisionType.CAN_ATTACH_AND_DROP; break; case RopeCollisionType.CAN_NOT_ATTACH_AND_CUT: FindObjectOfType <GameManager> ().setText(RopeCollisionType.CAN_NOT_ATTACH_AND_CUT.ToString()); colideObject = other.gameObject; stopRope(); collisionType = RopeCollisionType.CAN_NOT_ATTACH_AND_CUT; break; case RopeCollisionType.CAN_NOT_ATTACH_AND_THROUGH: FindObjectOfType <GameManager> ().setText(RopeCollisionType.CAN_NOT_ATTACH_AND_THROUGH.ToString()); colideObject = other.gameObject; collisionType = RopeCollisionType.CAN_NOT_ATTACH_AND_THROUGH; break; } } if (!isRopeLaunched) { collisionType = RopeCollisionType.NONE; } }
public void stopRope() { isRopeLaunched = false; isRopeAttached = false; colideObject = null; enabled = false; lineRenderer.SetPosition(0, Vector3.zero); lineRenderer.SetPosition(1, Vector3.zero); collisionType = RopeCollisionType.NONE; transform.position = player.transform.position; transform.parent = player.transform; GetComponent <CircleCollider2D> ().isTrigger = false; rigidBody2D.isKinematic = true; }