-
Notifications
You must be signed in to change notification settings - Fork 0
5. Vector Math
The dot product measures the similarity between two vectors in terms of direction. Mathematically, the dot product of vectors A and B (written as A·B) can be calculated as: In this equation, theta is the angle between the two vectors, |A| is the magnitude of vector A, and |B| is the magnitude of vector B.
What the dot product tells us: If A·B > 0 the vectors generally point in the same direction. If A·B < 0 they point in the opposite direction. If A·B = 0 they are perpendicular.
The lookVector helps determine the direction an object should face to look at a target. You obtain this vector subtracting an object's position from the target's position and normalizing the result:
How these is used in Godot:
Image from Godot Documentation
It is used primarily in facing, or seeing if one entity is facing another entity. In this case, for Zombie A, vector fa is the direction vector (also known as the lookVector) - it is used to then calculate vector fa or the vector between point A and B. Then we take the dot product A·AP and if this value is > 0 that means that Zombie A is facing the player, if it is <=0 the Zombie is not facing the player.
Read more about this: Godot Documentation