예제 #1
0
    Vector2 CalculateWallJumpVelocity(WallDirection wallDirection)
    {
        if (jumpInputManager.DetectInput(wallDirection))
        {
            Physics.gravity = new Vector3(0, zeroGravityAugment, 0);

            if (jumpInputManager.HoldTimer == 0 && wallDirection != WallDirection.None)
            {
                // Converts information about nearby walls into an integer multiplier for our x velocity.
                int xDir = ConvertXDirection(wallDirection);

                Vector2 newVelocity = new Vector3(xDir * jumpXVelocity, jumpCumulativeVelocity + playerBody.velocity.y);

                if (newVelocity.y < minJumpVelocity)
                {
                    newVelocity = new Vector3(xDir * jumpXVelocity, minJumpVelocity);
                }
                else if (newVelocity.y > maxJumpVelocity)
                {
                    newVelocity = new Vector3(xDir * jumpXVelocity, maxJumpVelocity);
                }

                return(newVelocity);
            }
        }
        else
        {
            Physics.gravity = new Vector3(0, standardGravityAugment, 0);
        }

        return(new Vector2(0, playerBody.velocity.y));
    }
    Vector2 CalculateJumpVelocity(bool grounded)
    {
        if (jumpInputManager.DetectInput(grounded))
        {
            if (Physics.gravity == new Vector3(0, standardGravityAugment, 0))
            {
                Physics.gravity = new Vector3(0, zeroGravityAugment, 0);
            }

            if (jumpInputManager.HoldTimer == 0 && grounded)
            {
                Vector2 newVelocity = new Vector3(0, jumpCumulativeVelocity + playerBody.velocity.y);

                if (newVelocity.y < minJumpVelocity)
                {
                    newVelocity = new Vector3(0, minJumpVelocity);
                }
                else if (newVelocity.y > maxJumpVelocity)
                {
                    newVelocity = new Vector3(0, maxJumpVelocity);
                }

                return(newVelocity);
            }
        }
        else
        {
            if (Physics.gravity == new Vector3(0, zeroGravityAugment, 0))
            {
                Physics.gravity = new Vector3(0, standardGravityAugment, 0);
            }
        }

        return(new Vector2(0, playerBody.velocity.y));
    }