Game Development Reference
In-Depth Information
and v is π/2 (90 degrees) then the dot product will be 0. If the dot product is greater than
zero, the angle will be less than π/2. If the dot product is less than zero, the angle between
the vectors will be greater than π/2.
This operation will be useful anytime we wish to test whether two vectors align towards
the same direction, this situation comes up often and we rely on the dot product to help us
understand what is going on in the game. For example, if we want to know if an enemy
is in front of the player, we would compute a direction vector towards each enemy v , then
compute the dot product against the player's forward direction f , if the dot product is less
than zero ( v • f < 0), the enemy is behind the player.
In another example, say we want to display a message on the UI when the player has been
spotted by a guard. During the game update we would compute the direction from each
guardtotheplayer,thenusingthedotproductagainsttheguard'sviewdirection. Ifthedot
product is greater than zero, meaning that the angle between the enemy's view direction
and the direction in which the player is at, is less than 90 degrees, then the player has been
spotted by this guard.
At times we may want to compute precisely what the angle is between two vectors, we can
use the dot product to find the angle. Recall the definition of the dot product:
We can solve for the angle Ɵ.
Then solve the inverse cosine:
Search WWH ::




Custom Search