Esempio n. 1
0
    void RunStatus()
    {
        switch (status)
        {
        case Status.idle:
            transform.localScale = new Vector3(1, 1, 1);
            movement.slideReady  = true;
            if (input.PressedJump())
            {
                movement.GroundedJump(groundedJumpForce);
            }
            break;

        case Status.walking:
            transform.localScale = new Vector3(1, 1, 1);
            movement.slideReady  = true;
            if (input.PressedJump())
            {
                movement.GroundedJump(groundedJumpForce);
            }
            break;

        case Status.crouching:
            transform.localScale = new Vector3(1, 0.7f, 1);
            if (input.PressedJump())
            {
                movement.GroundedJump(groundedJumpForce);
            }
            break;

        case Status.sliding:
            transform.localScale = new Vector3(1, 0.5f, 1);
            if (input.PressedJump() && groundDetector.isGrounded)
            {
                movement.SlideJump(groundedJumpForce, rb.velocity * slideJumpRange);
            }
            break;

        case Status.wallrunning:
            wallrunTimer  += Time.deltaTime;
            wallrunGravity = (wallrunTimer * wallrunTimer) * wallrunFallSpeed;

            if (wallrunDetector.contactR)
            {
                wallrunCamLerp  += Time.deltaTime / wallrunCamLerpSpeed;
                wallrunNormalNew = Vector3.Cross(Vector3.up, wallrunDetector.wallNormal);
                if (wallrunNormalNew != wallrunNormalOld)
                {
                    wallrunCamLerp = 0.0f;
                    wallrunLerpTargetGetOnceTrigger = false;
                }
                if (!wallrunLerpTargetGetOnceTrigger)
                {
                    wallrunLerpTargetGetOnceTrigger = true;
                    wallrunStartDir = transform.forward;
                }
                transform.forward = Vector3.Slerp(wallrunStartDir, wallrunNormalNew, wallrunCamLerp);
                wallrunNormalOld  = wallrunNormalNew;
            }
            else if (wallrunDetector.contactL)
            {
                wallrunCamLerp  += Time.deltaTime / wallrunCamLerpSpeed;
                wallrunNormalNew = Vector3.Cross(wallrunDetector.wallNormal, Vector3.up);
                if (wallrunNormalNew != wallrunNormalOld)
                {
                    wallrunCamLerp = 0.0f;
                    wallrunLerpTargetGetOnceTrigger = false;
                }
                if (!wallrunLerpTargetGetOnceTrigger)
                {
                    wallrunLerpTargetGetOnceTrigger = true;
                    wallrunStartDir = transform.forward;
                }
                transform.forward = Vector3.Slerp(wallrunStartDir, wallrunNormalNew, wallrunCamLerp);
                wallrunNormalOld  = wallrunNormalNew;
            }
            else if (!wallrunDetector.contactL && !wallrunDetector.contactR)
            {
                wallrunNormalNew = Vector3.zero;
                wallrunNormalOld = Vector3.zero;
                wallrunCamLerp   = 0.0f;
            }
            if (input.PressedJump())
            {
                wallrunGravity = 0.0f;
                wallrunTimer   = 0.0f;
                rb.velocity    = new Vector3(rb.velocity.x, 0, rb.velocity.z);
                movement.WallJump(wallJumpHeight, wallJumpRange, wallJumpPushoff, new Vector3(cam.transform.forward.x, 0, cam.transform.forward.z), wallrunDetector.contactR ? -transform.right : transform.right);
            }
            break;

        case (Status.climbing):
            climbTimer  += Time.deltaTime;
            climbGravity = (climbTimer * climbTimer) * climbHeight;
            climbGravity = Mathf.Clamp(climbGravity, 0.0f, 9.5f);
            break;

        case (Status.airborne):
            transform.localScale = new Vector3(1, 1, 1);
            if (input.PressedJump() && airJumpChargeAvailable > 0)
            {
                airJumpChargeAvailable--;
                movement.AirborneJump(airborneJumpForce, airborneJumpControl, cam.transform.forward);
            }
            if (input.ReleasedDash() && dashCooldownTimer >= dashCooldown)
            {
                dashCooldownTimer = 0.0f;
                Vector3    dashTarget;
                RaycastHit hit;
                if (Physics.Raycast(transform.position, cam.transform.forward, out hit, dashDist))
                {
                    dashTarget = transform.position + cam.transform.forward * (hit.distance - 0.5f);
                }
                else
                {
                    dashTarget = transform.position + cam.transform.forward * dashDist;
                }
                StartCoroutine(movement.Dash(dashSpeed, transform.position, dashTarget));
            }
            break;

        case (Status.dashholding):
            Time.timeScale      = dashSlowMoFactor;
            Time.fixedDeltaTime = Time.timeScale * 0.02f;

            Vector3    dashTargetMark;
            RaycastHit hitt;
            if (Physics.Raycast(transform.position, cam.transform.forward, out hitt, dashDist))
            {
                dashTargetMark = transform.position + cam.transform.forward * (hitt.distance - 0.5f);
                Instantiate(dashTargetMarkerWall, dashTargetMark, Quaternion.identity);
            }
            else
            {
                dashTargetMark = transform.position + cam.transform.forward * dashDist;
                Instantiate(dashTargetMarkerAir, dashTargetMark, Quaternion.identity);
            }
            break;
        }
    }