【问题标题】:Rotate player on z axis while walking行走时在 z 轴上旋转播放器
【发布时间】:2019-12-13 23:46:49
【问题描述】:

我目前正在进行一个我的角色必须移动的新游戏。当我的角色向前走并且我在 z 轴上旋转它时,它只是旋转而不是沿着新的 z 轴走。

void Update()
{      
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            anim.SetInteger("Condition", 1);
            moveDir = new Vector3(0, 0, 1);
            moveDir *= speed;
            moveDir = transform.TransformDirection(moveDir);
        }
        if (Input.GetKeyUp(KeyCode.W))
        {
            anim.SetInteger("Condition", 0);
            moveDir = new Vector3(0, 0, 0);
        }
        moveDir.y -= gravity * Time.deltaTime;
        controller.Move(moveDir * Time.deltaTime);
    }
    rot += Input.GetAxisRaw("Horizontal") * rotSpeed * Time.deltaTime;
    transform.eulerAngles = new Vector3(0, rot, 0);        
}

}

我希望能够在改变 z 轴的同时向前走,而不是走路然后停下然后再走。

【问题讨论】:

  • 可能是因为移动方向覆盖了您的旋转

标签: c# unity3d


【解决方案1】:

您不能使用 CharacterController 执行此操作,因为您对 controller.move() 的调用会覆盖旋转……您需要编写自定义移动函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多