domingo, 3 de abril de 2016

BP Compendium: Dot product

Dot product

Dot product can be used to verify the relationship between two vectors, for example, if they are perpendicular or parallel.


  • A: Vector A.
  • B: Vector B.


  • Return Value: Float value representing the dot product between vectors A and B.

Example Usage

If the two vectors are normalized, the dot product is equal to the cosine of the angle formed between the vectors and can range from -1 to 1. This image shows some examples of dot product between two vectors.

Click to enlarge

In the script below, an enemy can only be destroyed if hit by a straight shoot. This test is done based on the dot product between the "Forward Vector" of the projectile and the vector "Hit Normal" of the enemy. They need to be opposite, so the dot product should be close to -1.

Click to enlarge