// Called each physics step.
        void CalculateVerticalMovement()
        {
            // If jump is not currently held and Ellen is on the ground then she is ready to jump.
            if (!m_Input.JumpInput && m_IsGrounded)
            {
                m_ReadyToJump = true;
            }

            if (m_IsGrounded)
            {
                // When grounded we apply a slight negative vertical speed to make Ellen "stick" to the ground.
                m_VerticalSpeed = -gravity * k_StickingGravityProportion;

                // If jump is held, Ellen is ready to jump and not currently in the middle of a melee combo...
                if (m_Input.JumpInput && m_ReadyToJump && !m_InCombo)
                {
                    // ... then override the previously set vertical speed and make sure she cannot jump again.
                    m_VerticalSpeed = jumpSpeed;
                    m_IsGrounded    = false;
                    m_ReadyToJump   = false;
                    myOnJump.Invoke(this);
                }
            }
            else
            {
                // If Ellen is airborne, the jump button is not held and Ellen is currently moving upwards...
                if (!m_Input.JumpInput && m_VerticalSpeed > 0.0f)
                {
                    // ... decrease Ellen's vertical speed.
                    // This is what causes holding jump to jump higher that tapping jump.
                    m_VerticalSpeed -= k_JumpAbortSpeed * Time.deltaTime;
                }

                // If a jump is approximately peaking, make it absolute.
                if (Mathf.Approximately(m_VerticalSpeed, 0f))
                {
                    m_VerticalSpeed = 0f;
                }

                // If Ellen is airborne, apply gravity.
                m_VerticalSpeed -= gravity * Time.deltaTime;
            }
        }
Exemple #2
0
    void Update()
    {
        isGrounded = Physics.Raycast(feet.position, Vector3.down * 2, 2f, GroundMask);
        _animator.SetBool("IsGrounded", isGrounded);

        if (Input.GetMouseButton(0) && isGrounded)
        {
            jumpForce = Mathf.Lerp(jumpForce, Stats[UpgradeNames.MaxJumpSpeed], Stats[UpgradeNames.JumpForceGainMultiplier] / 20);
            _animator.SetBool("IsCharging", true);
            _animator.speed = 1f + (jumpForce / 50f);
            cubeRenderer.material.Lerp(cubeRenderer.material, ChargingJumpMat, Stats[UpgradeNames.JumpForceGainMultiplier] / 20);
            jumpCharging?.Invoke();
        }

        if (Input.GetMouseButtonUp(0) && (isGrounded || jumpCount > 0))
        {
            jumpTriggered = true;
            _animator.SetBool("IsCharging", false);
            dustParticle.Play();
            AudioManager.instance.PlayAudioOneShot("Player Jump");
            jumpCount--;
            if (jumpCount == 1)
            {
                GameManager.instance.CreateFloatingText("Last Jump", jumpCountTextColor);
            }
            else
            {
                GameManager.instance.CreateFloatingText($"{jumpCount}", jumpCountTextColor);
            }
            jumped?.Invoke();
        }

        if (isGrounded)
        {
            ResetJumpCount();
            if (!_animator.GetBool("IsCharging"))
            {
                cubeRenderer.material.Lerp(cubeRenderer.material, defaultMaterial, .2f);
            }
        }
        else
        {
            if (_rb.velocity.y >= -0.5f)
            {
                cubeRenderer.material.Lerp(cubeRenderer.material, defaultMaterial, .2f);
            }
            else if (_rb.velocity.y <= -18f)
            {
                cubeRenderer.material.Lerp(cubeRenderer.material, ChargingJumpMat, .03f);
            }
        }

        if (jumpCount > 0)
        {
            JumpTarget.SetActive(true);
        }
        else
        {
            JumpTarget.SetActive(false);
        }

        GraphicsCube.transform.localEulerAngles = new Vector3(0f, 0f, transform.eulerAngles.z);

        if (_rb.velocity.y < -32f)
        {
            DestroyedCube.SetActive(true);
            foreach (var rb in DestroyedCube.GetComponentsInChildren <Rigidbody>())
            {
                rb.AddExplosionForce(20f, transform.position, 20f, 0f, ForceMode.Impulse);
            }
            AudioManager.instance.PlayAudioOneShot("Mine");
            playerDied?.Invoke();
            KillCube();
        }
    }