📜  修复对角线移动统一 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:16.386000             🧑  作者: Mango

代码示例1
If you watched Brackey's tutorial, just paste the following in after "float z = Input.GetAxis("Vertical");":

        //This marked area below is the code you would want to scrap
        /*
        Vector3 move = (transform.right * x + transform.forward * z);

        controller.Move(move * speed * Time.deltaTime);
        */

        //This here below is the new code. It works just fine!
        Vector3 forwardMovement = transform.forward * z;
        Vector3 rightMovement = transform.right * x;

        controller.SimpleMove(Vector3.ClampMagnitude(forwardMovement + rightMovement, 1.0f) * speed);