Example #1
0
    private void KeepJumping()
    {
        currentJumpStrength -= (gravityDecreasePerSecond * Time.deltaTime);

        rb.velocity = new Vector2(rb.velocity.x, currentJumpStrength);

        if (!jumpButtonDown ||
            Time.time - timeStartedJumping >= MaxTimeToHoldJump || IsDead)
        {
            JumpingState = JumpingStateEnum.Jumping;
        }
    }
Example #2
0
    private void CheckAndBonk()
    {
        if (JumpingState == JumpingStateEnum.Start &&
            CheckIsUnderCeiling())
        {
            Play(gameObject, LandSound);

            JumpingState = JumpingStateEnum.Jumping;
            rb.velocity  = new Vector2(rb.velocity.x, 0);
            rb.position  = new Vector2(rb.position.x, Mathf.Round(rb.position.y) - 2f);
        }
    }
Example #3
0
    private void HandleJumpState()
    {
        CheckAndBonk();

        if (JumpingState == JumpingStateEnum.Start)
        {
            KeepJumping();
        }

        if (JumpingState == JumpingStateEnum.Jumping)
        {
            if (isOnFloor)
            {
                JumpingState = JumpingStateEnum.NotJumping;
            }
        }
    }
Example #4
0
    public void Jump()
    {
        if (IsDead)
        {
            return;
        }

        var canJump = (isOnFloor && JumpingState == JumpingStateEnum.NotJumping) ||
                      (canCoyoteJump && !isOnFloor);

        if (!canJump)
        {
            return;
        }

        Play(gameObject, JumpSound);

        JumpingState        = JumpingStateEnum.Start;
        timeStartedJumping  = Time.time;
        currentJumpStrength = JumpHoldStrength;
    }