Hello, I was interested in trying to understand how to use the FOV using the dot product.
The solution in the video is :
if abs(direction_to_Player.angle_to(NPC_facing_direction)) < deg2rad(FOV_TOLERANCE):
a lot simpler but for some reason is harder to remember for me.
I was reading the documentation and watching some videos about vector maths and I figured out I get the same results with:
if direction_to_Player.dot(NPC_facing_direction) > cos(deg2rad(FOV_TOLERANCE)):
since COS a = A . B, the FOV_TOLERANCE
is in radians and we want values from -1 to 1 to represent the angle I put cos(deg2rad(FOV_TOLERANCE))
.
To approach that solution is harder but I think is easier to remember how it works once you know the formula.
I’m not sure if I’m clear explaining this approach but I hope is useful or interesting for someone.