Members - Reputation: 113
Posted 12 January 2013 - 03:05 AM
Members - Reputation: 612
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/
Crossbones+ - Reputation: 3984
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.
Members - Reputation: 147
Posted 15 January 2013 - 04:21 AM
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.