예제 #1
0
    private void FixedUpdate()
    {
        float fixedDeltaTime = Time.fixedDeltaTime;
        bool  isGrounded     = IsGrounded();
        bool  isCrouching    = playerInput.IsCrouching();

        if (isGrounded == true)
        {
            fallSpeed = 0;
        }
        else
        {
            fallSpeed += gravity * fixedDeltaTime / 2;
        }

        if (isGrounded == true && isCrouching == false)
        {
            fallSpeed += velocityDirection.y * fixedDeltaTime * jumpForce;
        }

        float MoveX = (velocityDirection.x * fixedDeltaTime) * moveSpeed;
        float MoveY = fallSpeed;
        float MoveZ = (velocityDirection.z * fixedDeltaTime) * moveSpeed;

        Vector3 movementThisFrame = transform.right * MoveX + transform.up * MoveY + transform.forward * MoveZ;

        characterController.Move(movementThisFrame);
    }