Guided Missle Lock

Member
Posts: 20
Joined: 2010.09
Post: #1
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]

Thomas.
http://www.rattansoftware.com
Groundhog Assault 3D (Apple App Store)
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
forward 180° up to a certain range?
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #3
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.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Member
Posts: 20
Joined: 2010.09
Post: #4
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.

Thomas.
http://www.rattansoftware.com
Groundhog Assault 3D (Apple App Store)
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #5
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.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #6
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?
Quote this message in a reply
Member
Posts: 20
Joined: 2010.09
Post: #7
I'm looking for a general approach. I'll be able to hande it from there.
Thanks.

Thomas.
http://www.rattansoftware.com
Groundhog Assault 3D (Apple App Store)
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #8
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.
Quote this message in a reply
Post Reply