统一对角线运动无效



我希望我的玩家在对角线方向上移动,这是我用来向下对角线移动的代码:

 if (Input.GetAxisRaw("Horizontal") > 0f && Input.GetAxisRaw("Vertical") < 0f)
 {
      front45 = true;
      rb.velocity = new Vector3(moveSpeed, -moveSpeed, 0f);
 }

然而刚性体2d不会在该方向上移动。它会上下左右移动,但永远不会倾斜。

front45=true只是为了让动画师知道何时更改动画。

我会尝试这样的东西:

float h = Input.GetAxisRaw("Horizontal") * Time.deltaTime;
float v = Input.GetAxisRaw("Vertical") * Time.deltaTime;
if (h != 0 && v != 0)
    front45 = true; //Not sure what this does, so I just left it inside the condition
rb.velocity = new Vector3(h * moveSpeed, v * moveSpeed, 0f);

这应该在任何方向上都有效。

最新更新