统一对角线运动不起作用
Unity Diagonal Movement Not Working
我希望我的播放器沿对角线方向移动,这是我用来沿对角线方向移动的代码:
if (Input.GetAxisRaw("Horizontal") > 0f && Input.GetAxisRaw("Vertical") < 0f)
{
front45 = true;
rb.velocity = new Vector3(moveSpeed, -moveSpeed, 0f);
}
但是 rigidbody2d 不会朝那个方向移动。它会上下左右移动,但不会对角线移动。
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);
这应该适用于任何方向。
我希望我的播放器沿对角线方向移动,这是我用来沿对角线方向移动的代码:
if (Input.GetAxisRaw("Horizontal") > 0f && Input.GetAxisRaw("Vertical") < 0f)
{
front45 = true;
rb.velocity = new Vector3(moveSpeed, -moveSpeed, 0f);
}
但是 rigidbody2d 不会朝那个方向移动。它会上下左右移动,但不会对角线移动。
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);
这应该适用于任何方向。