Advertisement

finding and angle relative to an object

Started by August 25, 2002 08:03 PM
1 comment, last by MrX02 22 years, 5 months ago
in my game i want to have rotating turrets on a 2D plane. The turrets know their target''s position and are supposed to rotate towards the target. but i can''t figure out how to find the smallest angle from the turret to the target. any ideas?
So you want to find the smallest angle between two vectors? Please make a search through the archive for ''Finding the angle between two vectors''. It has been discussed countless times.

If this is not your problem, please be more specific.

Cédric
Advertisement


                         SOLUTION#@ = (unknown angle)#/ = division#| | = magnitude of vector" "#a, b = vectors           "DOT PRODUCT" ===  [@ = a.b/cos|a||b|]

example: Ok, your center of rotation is the origin or a local system of your turret axle. The two vectors which cross at the
origin will be the turret "line-of-fire"(the barrel-what have you) and the objects "line" to the turrets origin. You're saying you want them to be the same vector in order for the "gun" to hit the object. To find the two vectors' angle between each other, or the degree of rotation the turret would have to turn, in order to be pointing(same vector) at the object, you need the
vector components. For simplicity, let's draw this out, The turret is at the grand fixed origin(0,0,0):
e.g.
#gun vector(a) = (1,2)#turret-to-object vector(b) = (9,0)#your unknown angle of potential rotation = @ = what you want!^||   a|  /| /            |/_@_______________b__>0,0LET'S DO THE MATH!!!@ = a.b/cos|a|b|{a.b = x1*x2 + y1*y2 + z1*z2a.b = 1*9 + 2*1a.b = 11}{|a|,|b| = squareroot_of(x^2 + y^2 + z^2)|a| = sqrt(1+4)|b| = sqrt(81) = 9}SO on your calc., divide "11" by ((sqrt(5))*(9))*cosine,and I think you may get the answer. hmmm. good post.*my_answer = 




[edited by - 3289432u on August 25, 2002 11:43:29 PM]

[edited by - 3289432u on August 25, 2002 11:44:14 PM]

This topic is closed to new replies.

Advertisement