Dot product is algebraically defined as the sum of the product of the corresponding vector component.

If we were to find the dot product of Vector A (Ax, Ay, Az) and Vector B (Bx, By, Bz), we would use this formula:

  • A•B = (Ax×Bx)+(Ay×By)+(Az×Bz)

Example

If the two input vectors are unit vectors (vectors with length of 1), the dot product outputs the cosine of the angles formed by those two vectors. If the two input aren't unit vectors, we can still find the cosine of the angle with two methods:

  • Normalize the two input vectors first before the dot product.

  • Get the output of the dot product and divide it by the product of the two input vectors' length.

We don't have an inverse cosine block, but we can create the script to find the angle:

Moving on to another example involving a stealth game, there is a guard facing a direction with a FOV of 90° (visually highlighted in green), and there is a ninja sneaking up on him. How can we check if the ninja is on the guard's sight?

The first input for the dot product is the direction that the guard is facing, the second input is the vector from the guard's position to the ninja's. Then we compare the cosine of the angle formed by those two vector with the cosine of half of FOV: