0 votes

E.G.

func _physics_process(delta):
    position += Vector2(1, 1).normalized() * velocity * delta

What does that .normalized() do? everyone says its setting a vector's length to 1. But what does that mean?

in Engine by (99 points)

1 Answer

+1 vote
Best answer

You can picture a vector as an arrow, pointing in some direction and having some length.

The vector (1, 1) has a length of 1.414 (by the Pythagorean theorem). Normalizing this vector sets its length to 1, so the vector becomes (0.7071, 0.7071).

Normalized vectors, since they have a length of 1 are very useful for representing directions, and you can then multiply them by any number to scale them to any length you need, such as the velocity length in the example you posted.

More details at the helpful docs link here:
https://docs.godotengine.org/en/stable/tutorials/math/vector_math.html

by (21,714 points)
selected by
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.