private void CheckGrappleHit() { Vector2 handPos = hand.position; Vector2 dir = (Vector2)grapplePoint - handPos; dir = dir.normalized; grappleLaunchTime += Time.deltaTime; if (grappleLaunchTotalTime < grappleLaunchTime) { // Debug.Log("Rope doesn't reach"); ropeRenderer.ClearRope(); onGrapple = false; return; } var distance = grappleLaunchCurve.Evaluate(grappleLaunchTime); RaycastHit2D hit; if (hit = Physics2D.Raycast(handPos, dir, distance, hingeLayer)) { ropeRenderer.MovePoint(0, handPos); //ropeRenderer.MovePoint(1,hit.collider.transform.parent.position); ropeRenderer.MovePoint(1, hit.collider.transform.position); ropeRenderer.RepaintRope(); AudioManager.instance.Play("GrappleHit"); if (hit.collider.tag == "StaticHinge") { swingStrafeController.StartSwing(hit.collider.transform); playerController.enabled = false; onGrapple = true; enabled = false; } else { //swingStrafeController.StartSwing(hit.collider.transform.position); //playerController.enabled = false; // ropeRenderer.ClearRope(); // onGrapple = false; ropeRenderer.ClearRope(); ropeBehaviour.Init(hit.collider.transform); onGrapple = false; } } else if (hit = Physics2D.Raycast(handPos, dir, distance, obstacleLayer)) { //Hit a obstacle ropeRenderer.ClearRope(); onGrapple = false; } //Nothing is hit yet else { ropeRenderer.MovePoint(0, handPos); ropeRenderer.MovePoint(1, handPos + dir * distance); ropeRenderer.RepaintRope(); } }
private void LateUpdate() { RopeRetraction(); if (groundDetector.GroundContact) { playerController.enabled = true; } else { UpdateRopePhysic(); playerController.enabled = false; } if (Input.GetKeyDown(KeyCode.Space)) { enabled = false; if (!groundDetector.GroundContact) { grappleHookController.enabled = true; playerController.enabled = true; playerController.Velocity = new Vector3(-angularSpeed * ropeLength * Mathf.Sin(angle), angularSpeed * ropeLength * Mathf.Cos(angle), 0) * angularToSpeed; } grappleHookController.enabled = true; playerController.enabled = true; playerController.Velocity = lastFrameVelocity / Time.deltaTime; ropeRenderer.ClearRope(); } UpdateRope(hand.position); }