We have a target, which is somewhere in the level, and a player that can move around and can aim anywhere. Now we want to calculate the distance between the players AIM and the TARGET.
How far off is the players aim from the target? - If this value is close to '0' we know the player is aiming at the target. We want to know this, since we like to calculate how far off the player was, when they fired a shot.
The following info is what we have:
- Target Vector(X, Y, Z) position/coords.
- Player Vector(X, Y, Z) position/coords.
- Player pitch & yaw.
So you defined the distance as the distance between the target point in the space and the line of aim. Note that you could also define the distance as the angle between the line connecting the player and the target and the line of aim.
Fortunately this is easy:
Point b is the prepandicular projection of the
Target
to the lineaim
:You can calculate the vector
a
from pitch and yaw with some formulae like these: