# Normalizing vectors

I don’t understand why you would need to normalize a vector. What is wrong with using the vector length?
and a simple scenario would be nice.

normalizing a vector makes it a ‘unit vector’

A unit vector is a vector of length 1.

This allows you to now use that unit vector in arithmetic scenarious that 1 is powerful due to the identity theorem.

So now if you want to say move in some direction at X units per second… you’d multiple the normalized vector representing direction by the float X for speed. Which would result in the correct velocity vector.

Where as if you didn’t normalize it before hand… any magnitude that the vector had would alter the speed, resulting in a velocity vector that was NOT accurate.

<0,2,0> * 5 = <0,10,0>
<0,1,0> * 5 = <0,5,0>

<0,2,0> has the same direction as <0,1,0>. But because it’s magnitude is 2, the resulting velocity <0,10,0> has a speed of 10… not the 5 we desired.

Note, there is nothing wrong with using the vector length. It’s about WHEN to use it and when not. Sometimes you need a normalized vector, other times you don’t. It all depends on what you’re doing.

1 Like

Thank you, that was quite simple to consume. Another thing will normalizing the vector shorten the vector length to 1?(change the vector poor does it keep its current vector length?

To sum up what you are saying i wrote this code

speed=5;
vecDiveSpeed=10;
vecDiveSpeed= speed*(vecDiveSpeed.normalized)

if vecDiveSpeed is normalized it will have a constant velocity of 5 if its not it won’t have a constant velocity.

A vector can be conceptualised as a direction and a length.

Normalising makes a vectors length 1. This is regardless of the original length.

In practical terms you normalise when you are interested in the direction of a vector, but not it’s length.

Simplest example is to have a movement script on a player with a reasonably high speed value * the movement vector. Forward/back/left/right will move at that speed but then move diagonally & watch how much faster it moves as the vector will be higher. E.g. A triangle with 2 sides of 1 unit will have the diagonal (hypotenuse) of square root of 2 (square root of 1squared + 1 squared) which I think is 1.4. That means if you had a speed value of 10 then moving horizontally or vertically you will have a movement value of 110 =10 bug if you moved diagonally you will be moving at 1.410=14. Normalising will bring all those vector values back to 1 so the player will move in each direction at the same movement speed.

1 Like

Thanks alot, that was the perfect example.