예제 #1
0
    void HandleFall()
    {
        bool jumpDown = false;

        if (touchControl && player.playerId == Common.PlayerId.TouchPlayer)
        {
            jumpDown = touchControl.GetButton(jumpButtonName);
        }
        else
        {
            jumpDown = Input.GetButton(inputJump) || Input.GetButton(jumpButtonName);
        }

        if (!IsGrounded)
        {
            if (!jumpDown)
            {
                gravity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
            }
            else
            {
                gravity += Vector3.up * Physics.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
            }
        }


        //Factor in attack fall speed requires MainAttackPlayer component;
        float fallSpeedFactor = 1;

        if (attack)
        {
            if (attack.IsAttacking())
            {
                fallSpeedFactor *= attack.attackFallSpeed;
            }
        }


        controller.Move(gravity * Time.deltaTime * fallSpeedFactor);
        IsGrounded = controller.isGrounded;

        if (gravity.y < 0 && IsGrounded)
        {
            gravity      = Vector3.zero;
            jumpVelocity = Vector3.zero;
            jumpCount    = maxJumpCount;
        }

        if (IsGrounded)
        {
            controller.slopeLimit = slopeLimit;
        }
        else
        {
            controller.slopeLimit = jumpSlopeLimit;
        }
    }