iDevGames Forums
Guided Missle Lock - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Guided Missle Lock (/thread-8404.html)



Guided Missle Lock - Ropeburn - Dec 11, 2010 01:32 PM

I'm adding guided missles to my game and would like them to lock onto a particular entity in my world. Parsing through the list of entities is not a problem. Rather, I'd like some feedback, thoughts or ideas for algorithms to acquire the lock. Thanks.[/align]


RE: Guided Missle Lock - skyhawk - Dec 12, 2010 01:09 AM

forward 180° up to a certain range?


RE: Guided Missle Lock - cmiller - Dec 12, 2010 02:17 AM

Factoring in range to target might be a good idea. I'm not a guided munitions expert or anything, but I was under the impression that radar lock had a range beyond which is wasn't able to achieve good tone.


RE: Guided Missle Lock - Ropeburn - Dec 13, 2010 10:16 PM

Yes. I was thinking of casting a ray for the view and seeing if any lockable entities were within a set range. I'm guessing that is how it is done.


RE: Guided Missle Lock - cmiller - Dec 13, 2010 11:36 PM

Unless you're planning on having shedloads (read: 1,000+) lockable entities in you entire game world, worrying too much about this algorithm is just premature optimization. I find that's it's a lot easier to optimize when you have something that's running slow, instead of optimizing before it's going slow.


RE: Guided Missle Lock - ThemsAllTook - Dec 14, 2010 08:50 AM

I've implemented this a couple of times before. Are you looking for help with a particular part of the algorithm, or are you not sure of the general approach to take?


RE: Guided Missle Lock - Ropeburn - Dec 14, 2010 09:20 AM

I'm looking for a general approach. I'll be able to hande it from there.
Thanks.


RE: Guided Missle Lock - ThemsAllTook - Dec 14, 2010 10:08 AM

As I recall, mine worked something like this:
  • Subtract the position of the target from the position of the missile and normalize it.
  • Take the cross product and dot product between the missile's current direction and that vector to get axis and angle.
  • Clamp the angle to some arbitrary maximum (or minimum if negative) so that the missile doesn't instantly reorient directly toward the target.
  • Rotate the missile along the computed axis/angle.
Based on earlier discussion in this thread, it sounds like determining which target to choose may be an issue. To get the closest object in front of you, I'd just loop through all of your objects, subtract their positions from your missile's position, check if dot product is positive, and if so, pick the one with the lowest squared distance from the missile.