关于CharacterController空中悬浮问题记录(Un

2020-02-25  本文已影响0人  木容虾

对于CharacterController有一个暗坑,就是上下楼梯问题,按照基本设置,上楼梯是完全没有问题的,但奇怪就奇怪在,人物一旦上去了,再下来就漂浮到空中了.这让人感觉就好像菜只做好了一半,谁能想得到,上楼梯不需要代码控制,下楼梯却需要,逼死强迫症.
具体解决如下:


        if (characterController.isGrounded)
        {
            // We are grounded, so recalculate
            // move direction directly from axes
            moveDirection =transform.forward;
            moveDirection *= speed;
        }

        // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
        // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
        // as an acceleration
        moveDirection.y -= gravity * Time.deltaTime;

        // Move the controller
        characterController.Move(moveDirection * Time.deltaTime);

上一篇 下一篇

猜你喜欢

热点阅读