• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

which side of my shooter

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

#1GM5  Members

Posted 12 January 2013 - 03:05 AM

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?

#2mrjones  Members

Posted 12 January 2013 - 03:45 AM

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/

#3slicer4ever  GDNet+

Posted 12 January 2013 - 03:50 AM

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.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#4r1ckparker  Members

Posted 14 January 2013 - 01:59 PM

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...

#5saaughmraat  Members

Posted 15 January 2013 - 04:21 AM

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, 15 January 2013 - 04:22 AM.

#6GM5  Members

Posted 19 January 2013 - 02:21 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.