Login

Fancade Wiki

Updated Dot Product.md (markdown)

... ...
@@ -8,9 +8,7 @@ If we were to find the dot product of Vector A (Ax, Ay, Az) and Vector B (Bx, By
8 8
## Example
9 9
10 10
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:
11
12 11
- Normalize the two input vectors first before the dot product.
13
14 12
- Get the output of the dot product and divide it by the product of the two input vectors' length.
15 13
16 14
[[/uploads/20210106_122008.jpg]]
... ...
@@ -23,6 +21,10 @@ Moving on to another example involving a stealth game, there is a guard facing a
23 21
24 22
[[/uploads/Screenshot_20210106-131627_Fancade.jpg]]
25 23
26
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:
24
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 position. Then we compare the cosine of the angle formed by those two vector with the cosine of half of FOV:
25
26
[[/uploads/Screenshot_20210106-135840_Fancade.jpg]]
27 27
28
[[/uploads/Screenshot_20210106-135840_Fancade.jpg]]
... ...
\ No newline at end of file
0
Let me explain the script:
1
- First we subtract the ninja's position by the guard's position (if it's the other way round, we get the vector from the ninja's position to the guard's position, that's the opposite of what we want). Then we normalize the vector before the dot product.
2
- For the guard's direction, we get the guard's current rotation and rotate the vector (0, 0, 1) by that rotation. This is only correct if we're assuming that the guard faces in that direction (0, 0, 1) if his current rotation is 0°, otherwise we use a different vector value. We don't have to normalize because we rotated the vector (0, 0, 1) which already has a length of one.
... ...
\ No newline at end of file
Fancade Wiki