Please Explain What The normalized Function Does

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


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?

:bust_in_silhouette: Reply From: kidscancode

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: