0

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.

  • I don't think you can really have a normal to a vector, since normals are for planes. A single vector doesn't define a plane (unless of course that vector IS the normal) – jhocking Sep 25 '14 at 20:22
  • So you understanding of the involved terminology is making it incredibly hard to understand the question. It sounds like you want a vector perpendicular to the vector and the direction of the camera. If so just take the cross product of the vector and camera direction vector. – ClassicThunder Sep 25 '14 at 20:45
  • 2
    For this sort of 3d stuff adding a picture of what you are talking about can be very helpful. – ClassicThunder Sep 25 '14 at 20:45
  • The author just chose two random vectors perpendicular to the given vector as an example. They simply set one of the components to zero in each case and solved from there using the dot product, there is nothing more to it. – jmegaffin Sep 25 '14 at 20:46
  • 1
    This question appears to be off-topic because it is about mathematics in a way that is unrelated to game development. – jmegaffin Sep 25 '14 at 20:47
  • I need to find a vector perpendicular to current. I have only 1 vector, not 2,3 ... This vector is players current direction vision. And I need to find left or right position of it. The whole problem is that we have an enemy, that is shooting at the player and I need to tell the player from which direction the enemy shoots. And I'm asking about only half a problem, cause I know, how to do the other half – Oleksandr Verhun Sep 25 '14 at 20:50
  • 1
    Hint: rotate the vector 90° around the vertical axis. – Marcks Thomas Sep 25 '14 at 21:23
  • 1
    bool is_left=dot(cross(forward, up), enemy_dir)>0; – JarkkoL Sep 26 '14 at 00:29

1 Answers1

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.

ilustration

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