Unity 角色控制器在斜面上的运动不清晰

问题描述 投票:0回答:1

我使用CharacterController 在Vector3(0, -1, 1) 方向上移动玩家,该方向与倾斜(45 度)平面法线相反。所以,我觉得性格就应该站在同一个位置上。但它沿 Vector3(0, 1, 1) 方向移动。有人可以解释一下为什么吗?是不是有碰撞的事情?

代码:

public class NewBehaviourScript : MonoBehaviour
{
    private CharacterController _controller;
    
    void Start()
    {
        _controller = GetComponent<CharacterController>();
    }
    
    void FixedUpdate()
    {
        Vector3 dir = new Vector3(0, -1, 1);
        _controller.Move(dir * Time.fixedDeltaTime);
        
        Debug.Log($"Dir: {dir}, Vel: {_controller.velocity}");
        Vector3 origin = transform.position + transform.right;
        DebugExt.DrawColored(Color.red).Vector(origin , dir * 2);
    }
}

image 1

image 2

image 3

我一直在改变不同的CC参数,没有任何改变

c# unity-game-engine physics
1个回答
0
投票

问题是CC本身根据平面角度处理和改变运动。 因此,要使角色在斜面 (45d) 上静止,运动矢量应该为 (0, -1, 0)。要使其向前移动(平行于平面),只需将运动向量设置为 (0, 0, 1)。 哦,我觉得这很奇怪,但它对标准化没有任何作用。因此,如果你在平面上向前移动角色,它的速度将为 (0, 1, 1)(大小 - sqrt(2))

示例

© www.soinside.com 2019 - 2024. All rights reserved.