I was watching a tutorial about Vectors in Unity, I understood the meaning of normalizing a vector but I wanna know why do we normalize a vector and if we don't what will happen ?
-
3\$\begingroup\$ I voted to close this question as "unclear what you are asking". There are lots and lots of different situations in Unity where you are working with vectors, and there are different reasons why you would normalize them. Please explain where these vectors come from and what they are used for. Then we can try to explain why you need to normalize them in this particular situation. \$\endgroup\$– PhilippCommented Aug 21, 2018 at 12:02
-
1\$\begingroup\$ Move spaceship from A to B. Get Direction by B - A. Set spaceship velocity to Direction. Their speed is now faster if they have to travel farther. By normalizing it first, there is a constant speed regardless of how far they have to travel. \$\endgroup\$– Evorlor ♦Commented Aug 21, 2018 at 21:46
-
\$\begingroup\$ @Philipp I wanted to move a character from one point to another with some speed. \$\endgroup\$– Abhinay Singh NegiCommented Aug 23, 2018 at 10:12
2 Answers
There are reasons someone might want to normalise a Vector, including dealing with directions. Normals on meshes, for example, are normalised, because you only care about their direction, not their length.
It also makes the math work, because if you have multiple normal vectors with different lengths, it would be impossible to calculate values (like lighting) in a uniform way.
There are operations that do not make sense when the vector is not normalized. Some examples:
- When you want to get the projection of a vector on another vector. You want to normalize the second one so that you only get its direction.
- When you are dealing with basis vectors in a Cartesian coordinate system. This is where matrix transformations and viewing in 3D space comes into play.
There are a lot more, but this is the gist of it.