# Implementing a homing missile [duplicate]

I'm having some trouble implementing a homing missile that satisfies what I'm looking for. I have already tried the Seeking and Arrival behaviours described in this link, but none of them were what I wanted. With Seeking, it winds up orbiting the object indefinitely, and Arrival is simply unavoidable.

I'm aiming for something similar to the missiles of this video and the ones of Super Meat Boy - avoidable missiles that nevertheless do the job. It actually looks like a mix of Seek and Arrival, or maybe even the Path Following behaviour described in the first link.

This is my idealized behaviour, with a user-controlled target:

Can I have some insight on the matter? I know that questions regarding homing missiles have popped up quite often around here, but I feel that I'm missing something basic. The first video has an explanation from its creator in the second answer of this question, I didn't quite grasp it, though.

• *sees nice drawings* "Is it Mutoh?" Yes, it's Mutoh. :) – Anko Mar 29 '13 at 18:17

What you have to do is estimate the future position of the moving target and steer towards that.

Here is bobobobo's super 5 step simplified process

## Derivation of eta: Sorry, I lied in the image above. The eta= formula comes from:

Some C code:

Vector3f exactTrackHeading( Vector3f mePos, // your pos
Vector3f target,  // position of what you're following
Vector3f velTarget, // velocity of your target
float a, // your capability to accelerate.
float &eta //, // impact time
//Vector3f& impactPos // exactly where you'll impact (if needed)
)
{
if( !a ){
error( "predictPos: accel cannot be 0" ) ;
a=EPS_MIN;
}
Vector3f toFollow = target - mePos ;
float d = toFollow.safeNormalize() ;

// his speed relative to me
Vector3f vTarget = velTarget - meVel ;

// Find the component of -vTarget along toFollow
float v = (-vTarget).dot( toFollow ) ;

// TIME ESTIMATE TO REACH MY TARGET
eta = -v/a + sqrtf( v*v/(a*a) + 2*d/a ) ;
// Use ETA to estimate WHERE we should aim.

Vector3f impactPos = target + vTarget * eta ;

return impactPos - mePos ; // ME TO IMPACTPT is suggested heading.
// len of this is dist to that target
}

• Alright here's what I understood: Let the Vrt vector be the target's speed - the rocket's speed; I create an acceleration towards the target; I estimate the time it'd take to arrive at the target with the rocket's speed being -Vrt and the aforementioned acceleration; I estimate the location of the target after the elapsed time with target's speed being Vrt; I aim my acceleration towards this location. I hope I got your writing right! c: – Mutoh Apr 9 '13 at 1:27
• I think OP is aware of this solution; it's mentioned as the "Arrival" behaviour. – congusbongus Apr 9 '13 at 1:28
• Pretty much! If what you're chasing has an acceleration of it's own, you'll get this neat "miss" behavior if the target is "evasive" enough. – bobobobo Apr 9 '13 at 2:28
• Insanely helpful answer. Thanks so much! – GoldenGremlin Aug 5 '19 at 18:05
• WANNA SEE IT IN ACTION?? – bobobobo Sep 5 '19 at 16:24

Try increasing the turn speed or slowing the missile based on flight time or distance to the target. Those would help prevent orbiting. (some of the comments in the last link hinted at this and is kind of depicted in your illustration)

EDIT: could also increase turn speed based on the velocity of the missile (probably more realistic but could still end up orbiting, haven't tried to code any of this yet though)

• I tried all matching combinations of increasing turn speed and slowing the missile based on flight time and distance, but it still doesn't work. "[...] but I've found that if I slow the missile, if it's going to miss, as it approaches the target, it effectively tracks and turns quicker and can hit the target" I wish I actually knew how he finds out whether it's 'going to miss', I'm almost certain this is the missing puzzle piece. – Mutoh Mar 29 '13 at 21:04
• I usually use degrees of rotation, if you are on target, the desired direction atan2(targety-selfy,targetx-selfx)*(180/PI) is going to be the same as your velocity vector atan2(yVelocity,xVelocity)*(180/PI) I am fairly sure XNA has atan2. and usually if the difference in the angles is greater than 180 I'll add or subtract 360 from the desired direction so it doesn't try to turn the wrong way. – UnderscoreZero Mar 29 '13 at 21:26
• What you may need to do here is more than just seek and arrival. I tried googling it, but there is one called hunt. You would need to take your current velocity, position, and heading, and determine the desired velocity to hit the target based on its movement. I've been messing with some test code and it looks like I'm getting the problem you're having. – UnderscoreZero Mar 29 '13 at 22:15
• By Hunt, would you rather mean Pursuing? red3d.com/cwr/steer/PursueEvade.html – Mutoh Mar 29 '13 at 22:21
• Right... that would be why I wasn't finding anything on google... – UnderscoreZero Mar 29 '13 at 22:57