what is Vector3.normalized?

What does it mean to normalize? What does this give me?


var normalized : Vector3
Returns this vector with a magnitude of 1 (Read Only).

When normalized, a vector keeps the same direction but its length is 1.0.

Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use Normalize function.

If the vector is too small to be normalized a zero vector will be returned.

See Also: Normalize function.

To normalize a vector means to make it unit length. In other words, regardless of what the length of the vector was prior to normalization, after normalization it will have the same direction but have a length of 1 (within numerical limits of course, and provided its original magnitude was large enough that the division could be performed).

Let me give a couple of examples of when you use normalisation…

When moving forward by 1 unit, the distance travelled is obviously 1 unit. Likewise moving right. What if you want to move diagonally? Moving forward 1 unit and right 1 unit gives you a diagonal distance of approx 1.4. That means you travel faster in a diagonal than forward or to the side.

Without normalisation, your move is (1, 0, 1) but, if you normalise, the actual move is (0.71, 0, 0.71). That’s the same as moving 0.71 forward and 0.71 to the right with a diagonal of 1 unit. Problem solved. You are now moving at a consistent speed in all directions.

Another example is when you want to move in a random direction. The best Unity function in 2D for this is Random.insideUnitCircle. That picks a random point in a circle of radius 1 with you at the centre. You’ve now got a direction.

However, that point might be near the centre or near the circumference. In other words, its magnitude (the distance) will vary. If you want to use that point as a direction, you should normalise it so that, although you have a random direction, the magnitude is always the same. You can then safely multiply it by your desired speed and Time.deltaTime and get the right velocity.

If you didn’t normalise then you would get different speeds, depending on where Unity gave you the random point.