Why is walking diagonally faster?

Your input has a length, and it isn't always 1.

Why is walking diagonally faster?

The problem

Two keys, two full speeds.

void Update(){    var input = new Vector3(        Input.GetAxis( "Horizontal" ), 0f,        Input.GetAxis( "Vertical" ) );     transform.position += input * speed * Time.deltaTime;}

Hold W and D and the input is ( 1, 0, 1 ). Its length is 1.41, so you move 41% faster.

What it costs

Diagonal wins every race.

Speed for each input, as a percent of normal:

W only
100 %
D only
100 %
W and D
141 %

Speedrunners find this in minutes. So does anyone in a hurry.

The fix in code

Cap the length at 1.

var input = new Vector3(    Input.GetAxis( "Horizontal" ), 0f,    Input.GetAxis( "Vertical" ) ); input = Vector3.ClampMagnitude( input, 1f ); transform.position += input * speed * Time.deltaTime;

Diagonal comes back to 1. Anything shorter is left alone.

Watch out

Why not normalized?

Normalizing stretches every input to 1, a stick pushed halfway included.

normalized
a half pushed stick runs
ClampMagnitude
a half pushed stick walks

Keyboards can't tell the difference. Gamepad players can.

The rule

Clamp the input, not the speed.

Diagonal fix
ClampMagnitude( v, 1 )
Keeps walking
on a half pushed stick
Avoid
normalized for input