Need normalization for direction vector in FirstPersonCamera?

On page 226, we normalize the direction vector before using its x and z values for translation.
Is that normalization necessary? direction seems to be just holding values for how much to translate for the forwardVector and rightVector. It by itself doesn’t seem to be a vector with geometric meaning, so this normalization seems confusing.
Am I missing something?

Thank you,
Raheel

It doesn’t make much of a difference here, because the numbers are so small.

However, yes, I think direction should be normalised. I am scaling a vector so that I am travelling the same distance no matter which direction I am going.

Let’s say forwardVector is [0, 0, 1] which would make rightVector [1, 0, 0], and translationAmount is 1.

If I take one step forward, then direction is [0, 0, 1].

No normalizing: transform.position = [0, 0, 1].
Normalizing: transform.position = [0, 0, 1].

The distance I have travelled is 1 for both vectors. (length of vector)

If I take one step diagonally forward and one to the right, then direction is [1, 0, 1]. Note that in this example, I’m not really taking two steps (one forward and one right). By pressing two keys, I am taking one step diagonally, and I should move the same distance as moving one forward.

No normalizing: transform.position = [1, 0, 1]. Distance is 1.414.
Normalizing: transform.position = [0.707, 0, 0.707]. Distance is 1

Notice that the distance travelled without normalizing is higher than if I just moved one forward.

(However, I have just noticed that transform.position += should be transform.position =. :woman_facepalming:)

1 Like

Thank you, that makes a lot of sense.
I have a follow up question: does it matter how “much” we travel as long as the composition of the two axes is the same? I am asking because in the end we multiply with a preference-based translationSpeed anyway, so the exact amount (1.414 vs. 1) from the vector calculation may not matter in terms of correctness.
I might still be missing something here!

It’s depend of what you are doing.
If you work on a car, plane simulation, it’s important because you have to keep the same speed of your movement in all direction.
But you can also imagine some game with take advantage on this « anomalie ».

1 Like

The translationspeed is a scalar value so that you can tweak the speed to match your input device.

You can imagine that over distance, an accumulation of 1.4 would be far greater than 1 so it would be faster to travel diagonally.

1 Like

That makes perfect sense. Thanks for clearing the confusion!

1 Like