Late to the party, but I helped someone else with this and thought I would share.
First, the .normalized
just normalizes the MAGNITUDE of the vector. magnitude = LENGTH of a vector. What does this mean? If we normalize the vector, we are setting the length of it to 1, while keeping the same DIRECTION of the vector. Thats really it. But now the why.
If you do not normalize it…and your vector happens to have a length of less then 1, then you will be multiplying v
in the v * m_camForward
part with a number less than 1…which will result in a slower move speed. We are adjusting most of our characters move speed based on the speed variables, so we always want to multiply our controller joystick input, v
, by a vector with a length of 1. The most important part of m_CamForward is the DIRECTION if gives us, it’s length always needs to be 1. This is really all .normalized does. It changes the vector around so that it’s length is 1, but it points the same way. lets do this in 2D. Imagine a line on a graph coming from (0,0) and ending at (0.5, 0.5). This line has a direction, and it has a length(around 0.707ish). If we wanted to use this in our code, and we had the joystick full forward (which would make v = 1) we would be multiplying 1*0.707 and get 0.707 as a direction. Now, this might seem like an issue…but imagine we are moving up and SLIGHTLY to the right… what does this look like? Well, V = 1 still (full forward on the joystick) and H would equal lets say .2. Why only .2? Because we are barely pushing right on the joystick. Full right on the joystick = 1. So now you can see that the lower the number the less movement in each axis we expect to move. So the Move code will read the 0.707 as “we are only pushing 3/4 of the way up one the joystick”. Now depending on how much you have moved/rotated your camera, the actual numbers that the move vector has might not make sense (if you rotated it 90 degrees, you would see 1 in the Z axis instead of the X for example) but this is just the code compensating for the camera angle. But the vector length of move still equals out to be 1, providing you are pushing fully in a single direction, because we first normalized the m_CamForward first.