How to get a direction and add a velocity to that direction?

Godot Version

4

Question

im trying to figure out how people calculate directions, if im watching a tutorial i just follow what they do for calculating directions but i dont actually understand it.
if someone could help that would be nice, thank you.

If you want a direction from point A to point B you just calculate the distance-vector:

var distance_vector = B.global_position - A.global_position

this vector points from point A to point B and has the length of the distance between them. If you want to use the direction to move in that direction you want to “normalize” the vector. Normalize means to reduce/increase the size of the vector to the length of 1, while keeping the same direction. Then you can add a speed to it:

velocity = distance_vector.normalized() * speed
1 Like

Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.