• Advertisement
Sign in to follow this  

which side of my shooter

This topic is 1829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Thank you for taking the time to read my post. If I have position vectorA and position vectorB and would like to know which side of position vectorA position vectorB is. In this case I would like to know if vectorB is on the left or right so I can orient my shooter to shoot left or right. How should it be done given that I have the two vectors, is it okay to check the x components of the vectors, is that acceptable in the industry or would you use the dot product somehow and if so what would be the efficient math that you would use?

Share this post


Link to post
Share on other sites
Advertisement

Are these actually position vectors, I mean vectors representing positions of shooter and target? Or do you mean that vectorA is the direction of the shooter and vectorB is a vector from the shooter's position to the target? I'm assuming the second case, because direction of the shooter must be known to make the decision of turning either left or right. In that case, I would use cross product. If cross product of vectorA and vectorB is less than 0, it's on one side and if greater than 0, it's on the other side. See http://www.gamedev.net/topic/289972-cross-product-of-2d-vectors/

Share this post


Link to post
Share on other sites

if your talking about a 2D world, and all objects are axis-aligned(with y being up), and the vector's are for the position of object A and object B then yes, you can compare the x coordinate to check, which way to face.

Share this post


Link to post
Share on other sites

Subtract one from the other, if the result is positive it's one way, if it's negative it's the other? That's just a guess by the way, I may be wrong...

Share this post


Link to post
Share on other sites
Assuming a 2D situation,

If position-A is ur shooter, and position-B is the target,

then the relative-target is given by substracting A from B.

if A=(x1, y1) and B = (x2, y2) then, A should be shooting towards the direction (x2-x1, y2-y1)

If you intend to rotate the shooter, the shooter should be rotated by an angle, calculated from "atan2(y2-y1, x2-x1)" Edited by saaughmraat

Share this post


Link to post
Share on other sites

Thanks for the replies.

 

It was 2D and they are position vectors so I have compared x's and now I know of alternatives for more complex situations, thanks again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement