private void Roping() { if (input.Roped && input.RightStick.magnitude > 0.2f) { var direction = input.RightStick; var rayHits = Physics2D.Raycast(transform.position, direction, 10.0f, 1 << LayerMask.NameToLayer("Ropables")); Detach(); ropeController = Instantiate(ropeControllerPrefab, transform.position, Quaternion.identity); audioSource.PlayOneShot(rope); if (rayHits.transform != null) { var targetRigidbody = rayHits.transform.GetComponent <Rigidbody2D>(); ropeController.AttachRope(rayHits.point, this, targetRigidbody); anchoredJoint2D.enabled = true; rigidbody.AddForce(direction.normalized); } else { var point = (Vector2)transform.position + (direction.normalized * 10); ropeController.AttachRope(point, this); Destroy(ropeController.LastRopeNode.GetComponent <RopeNode>().gameObject); ropeController = null; AnchoredJoint2D.enabled = false; } } else if (input.RopeUp) { Detach(); } if (ropeController != null && ropeController.LastRopeNode != null) { float horizontal = input.LeftStick.x; if (horizontal != 0) { Vector2 ropeDirection = (transform.position - ropeController.LastRopeNode.position).normalized, swingDirection = Quaternion.Euler(0, 0, 90 * Mathf.Sign(horizontal)) * ropeDirection; Vector2 force = (ropeDirection + swingDirection) * ropeSwaySpeed; rigidbody.AddForceAtPosition(force, transform.position + new Vector3(0, -1)); } } else { grabCooldown += Time.deltaTime; } if (currentRopeNode != null || (ropeController != null && ropeController.IsAttached)) { float vertical = input.LeftStick.y; if (vertical != 0 && Mathf.Abs(vertical) > 0.75f) { float check, timeCheck = currentRopeNode != null ? verticalTime : verticalRopeLengthTime; if (vertical < 0) { check = verticalDown += Time.deltaTime; verticalUp = 0.0f; } else { check = verticalUp += Time.deltaTime; verticalDown = 0.0f; } if (check >= timeCheck) { VerticalInput(vertical); verticalUp = 0.0f; verticalDown = 0.0f; } } } }