private void UpdateInput() { if (Input.GetMouseButton(0)) { // Find mouse position Vector3 mouseInput = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10); Vector2 mouseClick = cam.ScreenToWorldPoint(mouseInput); // Find ray direction and raycast Vector2 rayDirection = mouseClick - (Vector2)this.transform.position; RaycastHit2D hit = Physics2D.Raycast((Vector2)this.transform.position, rayDirection, grapple.grapplingHookRange, ~(1 << grapple.playerLayer)); float angle = angleStep; Quaternion rot; // If the raycast does not hit anything, loop raycast until object is hit while (hit.collider == null && angle < angleTolerance) { rot = Quaternion.AngleAxis(angle, Vector3.forward); hit = Physics2D.Raycast((Vector2)this.transform.position, rot * rayDirection, grapple.grapplingHookRange, ~(1 << grapple.playerLayer)); if (hit.collider != null) { break; } rot = Quaternion.AngleAxis(-angle, Vector3.forward); hit = Physics2D.Raycast((Vector2)this.transform.position, rot * rayDirection, grapple.grapplingHookRange, ~(1 << grapple.playerLayer)); angle += angleStep; } // if something is hit, and that is not the player if (hit.collider != null && hit.transform.tag != "Player" && swingReady == true && hit.transform.tag == "Anchor") { grapple.AttachRope(hit.point); GameObject.FindGameObjectWithTag("Player").GetComponent <ArmCursorFollow> ().enabled = false; } } // Check for rope release else // if(Input.GetMouseButtonUp(1)) { grapple.ReleaseRope(); GameObject.FindGameObjectWithTag("Player").GetComponent <ArmCursorFollow> ().enabled = true; } // Setting reeling and paying out grapple.reeling_in = Input.GetMouseButton(1); //grapple.paying_out = Input.GetKey(KeyCode.X); }
private void UpdateInput() { if (Input.GetMouseButtonDown(1)) { // Find mouse position Vector3 mouseInput = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10); Vector2 mouseClick = cam.ScreenToWorldPoint(mouseInput); // Find ray direction and raycast Vector2 rayDirection = mouseClick - (Vector2)this.transform.position; RaycastHit2D hit = Physics2D.Raycast((Vector2)this.transform.position, rayDirection, grapple.grapplingHookRange, ~(1 << grapple.playerLayer)); float angle = angleStep; Quaternion rot; // If the raycast does not hit anything, loop raycast until object is hit while (hit.collider == null && angle < angleTolerance) { rot = Quaternion.AngleAxis(angle, Vector3.forward); hit = Physics2D.Raycast((Vector2)this.transform.position, rot * rayDirection, grapple.grapplingHookRange, ~(1 << grapple.playerLayer)); if (hit.collider != null) { break; } rot = Quaternion.AngleAxis(-angle, Vector3.forward); hit = Physics2D.Raycast((Vector2)this.transform.position, rot * rayDirection, grapple.grapplingHookRange, ~(1 << grapple.playerLayer)); angle += angleStep; } // if something is hit, and that is not the player if (hit.collider != null && hit.collider.gameObject.layer != grapple.playerLayer) { grapple.AttachRope(hit.point); } } // Check for rope release else if (Input.GetMouseButtonUp(1)) { grapple.ReleaseRope(); } // Setting reeling and paying out grapple.reeling_in = Input.GetKey(KeyCode.LeftShift); grapple.paying_out = Input.GetKey(KeyCode.LeftControl); }