Answers for "fix diagonal movement unity"

C#
0

fix diagonal movement unity

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);
Posted by: Guest on August-18-2021

C# Answers by Framework

Browse Popular Code Answers by Language