14
\$\begingroup\$

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:

enter image description here

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ *sees nice drawings* "Is it Mutoh?" Yes, it's Mutoh. :) \$\endgroup\$
    – Anko
    Mar 29, 2013 at 18:17

2 Answers 2

8
\$\begingroup\$

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

enter image description here

1. Initial picture of the system.


enter image description here

2. Really what we are doing here is subtracting the rocket's velocity from both bodies in the system, so the rocket is effectively "stationary", and the target is moving


enter image description here

3. vc is really the scalar speed at which the gap between the 2 bodies is closing.


enter image description here

4. Must not have a=0! If a=0, then eta=inf, which makes sense

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

enter image description here


enter image description here

Some C code:

Vector3f exactTrackHeading( Vector3f mePos, // your pos
      Vector3f meVel, // your speed
      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
}
\$\endgroup\$
5
  • \$\begingroup\$ 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: \$\endgroup\$
    – Mutoh
    Apr 9, 2013 at 1:27
  • \$\begingroup\$ I think OP is aware of this solution; it's mentioned as the "Arrival" behaviour. \$\endgroup\$ Apr 9, 2013 at 1:28
  • \$\begingroup\$ 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. \$\endgroup\$
    – bobobobo
    Apr 9, 2013 at 2:28
  • 1
    \$\begingroup\$ Insanely helpful answer. Thanks so much! \$\endgroup\$
    – DyingIsFun
    Aug 5, 2019 at 18:05
  • \$\begingroup\$ WANNA SEE IT IN ACTION?? \$\endgroup\$
    – bobobobo
    Sep 5, 2019 at 16:24
0
\$\begingroup\$

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)

\$\endgroup\$
10
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Mutoh
    Mar 29, 2013 at 21:04
  • \$\begingroup\$ 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. \$\endgroup\$ Mar 29, 2013 at 21:26
  • \$\begingroup\$ 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. \$\endgroup\$ Mar 29, 2013 at 22:15
  • \$\begingroup\$ By Hunt, would you rather mean Pursuing? red3d.com/cwr/steer/PursueEvade.html \$\endgroup\$
    – Mutoh
    Mar 29, 2013 at 22:21
  • \$\begingroup\$ Right... that would be why I wasn't finding anything on google... \$\endgroup\$ Mar 29, 2013 at 22:57

Not the answer you're looking for? Browse other questions tagged .