# How do I stop my top down player from moving faster when they move diagnoally.

Here’s my movement script.

``````public class PlayerMovement : MonoBehaviour
{
public float playerSpeed;
public float defaultSpeed = 5;

void Start()
{
playerSpeed = defaultSpeed;
playerRigidbody = GetComponent<Rigidbody>();
playerCamera = FindObjectOfType<Camera>();
}
void Update()
{

Vector3 currPosit = transform.position;
Quaternion currRot = transform.rotation;
if (currPosit.y != 1)
{
transform.position = new Vector3(currPosit.x, 1, currPosit.z);
}
if (currRot.x != 0)
{
transform.rotation = new Quaternion(0, currRot.y, currRot.z, currRot.w);
}
playerInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
playerVelocity = playerInput * playerSpeed;

//Follows where the player's mouse is pointed.
Ray cameraRay = playerCamera.ScreenPointToRay(Input.mousePosition);
Plane floorPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;

if (floorPlane.Raycast(cameraRay, out rayLength))
{
Vector3 whereToLook = cameraRay.GetPoint(rayLength);
Debug.DrawLine(cameraRay.origin, whereToLook, Color.red);

transform.LookAt(new Vector3(whereToLook.x, transform.position.y, whereToLook.z));
}

}
void FixedUpdate()
{
playerRigidbody.velocity = playerVelocity;
}
}
``````

You need to normalize the playerInput Vector if its magnitude is bigger than 1.

Your axis ranges from -1.0 to 1.0. If you only move horizontally then the resulting vector is (1.0, 0, 0).
The magnitude of this vector is 1 → magnitude = sqrt(1.0² + 0² + 0²) = 1.

But if you move diagonally then the resulting vector is (1.0, 0, 1.0). And the magnitude of this vector is
sqrt( 1² + 0² + 1²) = sqrt(2) = 1.414…

And thats the problem. In this case the magnitude should also be 1 to make your character not move faster when walking diagonally. Normalizing a vector makes the vector to have a magnitude of 1. This is done by dividing each component of the vector by its magnitude. In this case the normalized vector is:

(0.707…, 0, 0.707…) because 1 / 1.414… = 0.707…

You do not have to normalize vectors yourself. The vector3 class has a method for that.

You have to normalized the movement speed. (playerInput * playerSpeed).normalized;