+1 vote

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.

in Engine by (16 points)

1 Answer

+2 votes
Best answer

You need to learn about vectors and transforms.

First, I would really recommend reading this:

And then this:

"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.

by (21,967 points)
selected by

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?

Nobody's perfect. :)

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.