Assume, that we have a player that has a vector direction. We have an enemy, that is shooting a player. And the task is to find out from which side the enemy is shooting. I know the algorithm, how to find this.We need to find the left vector and then do a dot product with enemy direction vector. The question is to find the left or right side of player's current vision and it means to find out the vector perpendicular to the player's vector. What's the easiest and the most least computation way to find it.
Asked
Active
Viewed 258 times
0
1 Answers
2
In order to compute left and right, you need the concept of "up". For instance, if you are flying a spaceship and performing a "barrel roll" then the concept of "up" changes and with it, left and right change as well although you are facing in the same direction. Up can be based on the plain the character is standing on or simply be an absolute direction.
Once you figure out "up" you simply do the cross product like @JarkkoL already explained.
If you multiply with the reverse order, you"ll get the opposite direction. So in other words, if left == cross(forward, up)
than right == cross(up, forward)
. You can also simply negate one to compute the other.

AturSams
- 10,517
- 1
- 32
- 58
-
also the handedness of your coordinate system will dictate which left/right vector you get – ratchet freak Sep 26 '14 at 09:35
-
Thx for the answer, I found out that my concept of up is irrelevant. That's because I only care about left/right it means that only plate XY considered. And then it comes to easy problem solving with just finding 2 dot products. – Oleksandr Verhun Sep 26 '14 at 09:58
bool is_left=dot(cross(forward, up), enemy_dir)>0;
– JarkkoL Sep 26 '14 at 00:29