what did function normalized do?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pass0

I saw this code at docs:

...
dir = Vector3()
...
input_movement_vector = input_movement_vector.normalized()
dir += -cam_xform.basis.z.normalized() * input_movement_vector.y
...

Why can the product of input_movement_vector.y and cam_xform.basis.z be assigned(+=) to vector dir?
And, why can cam_xform.basis.z.normalized() be used? I saw kidscancode said “you can’t normalize only the x component”.
I can’t understand that.

:bust_in_silhouette: Reply From: kidscancode

You need to learn about vectors and transforms.

First, I would really recommend reading this:

And then this:
http://kidscancode.org/godot_recipes/math/transforms/

“Normalizing” means setting a vector’s length to 1.

transform.basis is made up of three vectors, x, y, and z, which represent the object’s local coordinate axes. So basis.z is a Vector3. See Transform for details.

That said, basis vectors are already normalized, so it’s not necessary to use normalized() on them.

Thank you for your answer.
But if I understand correctly, you say “basis.z” doesn’t need to use “normalized()”, and docs does have code like that, which means DOCS is wrong, right?

pass0 | 2019-06-20 15:48

Nobody’s perfect. :slight_smile:

Normalizing an already normalized vector doesn’t hurt, it just doesn’t do anything.

kidscancode | 2019-06-20 16:03

I’ll try to help modify this.(‾◡◝)
Thanks, again.

pass0 | 2019-06-20 16:17