Missile targeting - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Design (/forum-5.html)
+--- Thread: Missile targeting (/thread-7589.html)
Missile targeting - Iceman - Aug 30, 2002 05:29 PM
Is there a place that has some coding tutorials (hopefully OpenGL) for missile targeting for the x and y coords. Also I've tried looking on google and gamasutra but found nothing.
Missile targeting - KenD - Aug 30, 2002 08:24 PM
I was pulling my hair about this same thing a couple of days ago and finally came up with something that works. I'm sure there is a more elegant way to do it though.
Basically I get the horizontal and vertical angles to the target and from that I calculate yaw and pitch inputs that I feed to the physics engine. It's a bit complicated but I get the vector to the target and my heading vector, construct a couple of shortest arc quaternions and get the angles from them.
Missile targeting - Iceman - Aug 31, 2002 10:03 AM
Hmm that sounds kind of complex :eek:. What about AI pathfinding would this be easy to work into missile targeting? I don't really know what it is, but it sounds very interesting.
Missile targeting - KenD - Aug 31, 2002 10:31 AM
I haven't dug into the path finding subject really but that's more about how to get computer controlled characters to find a way from point A to point B, avoiding obstacles and such. This may sound like what a missile is doing too, going from point A to point B but it's not really the same thing. In the case of a missile you know where the target is and it usually goes straight to it. It doesn't try to avoid obstacles.
The problem with a missile is how to make it steer towards the target in a 3D environment and I solved it as I described above. I find out how much off course I am (the angles) and then try to minimize those angles.
I haven't found a ready made solution to the problem so I had to combine several things like getting the direction to the target, my direction, getting the angles for how much I'm off and then steer in the opposite direction to minimize the difference.
Missile targeting - Iceman - Sep 1, 2002 12:19 PM
Quote:Originally posted by KenD
Ok I know how to make the vectors work with an angle, but what is the formula to find the minimum angle?
Missile targeting - w_reade - Sep 1, 2002 01:41 PM
I think this should work:
if you have two normalised vectors: the first pointing in the direction of the target and the second pointing in the direction of the missileÖ
Öthen their vector cross product is an axis vector for the rotation that will take one onto the other, and their vector dot product is the cosine of the angle between them.
If they aren't normalised you'll get a non-unit axis vector and plain wrong inverse cosines, so normalise them.
You should be able to optimise slightly by only bothering to steer if the dot product is > 0.95 or so - this should save needless course-correction calculations when the missile is on target.
edit - gibberish
Missile targeting - Iceman - Sep 2, 2002 04:09 PM
How do I find the angle? I know what the opposite and adjacent sides are (5,5). I've tried looking in my Algebra2 book, but none of the functions I thought would work did.
Missile targeting - Iceman - Sep 2, 2002 06:55 PM
Ok I got it finally! Been searching google all day and I finally figured out that I was forgeting to translate the radians into degrees. Here's how I got it: atan (5/5) * 180/M_PI .
Missile targeting - KittyMac - Sep 2, 2002 09:50 PM
A simpler, probably faster (yet less precise) way to do this is to create a vector which represents the velocity of the missile. Then get the distance (use the fast formula by not calling sqrt, the squared distance is fine for comparison) for the missile to the target if the missile continues on the same path. Next, get the distance from the target if the missile turns to clockwise this turn, and also if the missile turns counter-clockwise this turn. The distance which is the shortest is the one which the missile should do (ie if turning left shortens the distance to the target, then do that). One side effect of this is that if the turn value is too large, the missile may orbit around the target. :-)
Another method which is better than the one proposed, yet more complicated, is to use quaternions and do linear interpolation between them. This, I believe, produces the best results.
In either case, if your game calls for having lots of missiles, you'll not be very optimized if you call any of the trig math functions (like atan). However, if you only have a couple it probably won't matter.
Missile targeting - Iceman - Sep 3, 2002 02:58 PM
I think I'm going to stick with what works for now. What you suggested in the first paragraph sounds almost exactly like what I'm doing now. Also I'll probably only use 2 or 3 at a time since the missiles seek out the player immediately on launch, and they go pretty fast too.
quaternions = yuck :eek: