Skip to main content
added 959 characters in body
Source Link
Martin Sojka
  • 5.7k
  • 31
  • 30

First of all, you should make all calculations about what acceleration to apply in the missile's frame of reference (that's where the missile is stationary and everything else moves around it, also often called "object coordinates" or "local coordinates" in game engines, though in our case we want the velocity to be exactly zero as well).

The idea then is not to aim for the target, but to aim for the place where the target will be at the estimated time of impact. So the general algorithm looks like this:

  1. Estimate how much time it will take for the missile to reach the target. If the target is flying directly at it (remember, the missile is stationary), it'sit can be as simple as calculating distance / speed, in other cases it can be more complicated. If the target can try and evade you won't be able to make a perfect estimate anyway, so it's ok to not be very precise.

  2. Assuming constant speed (1st degree estimate) or constant acceleration (2nd degree estimate) of the target, calculate where it will be at the estimated time above.

  3. Calculate acceleration which will lead to the missile to be at roughly the same spot at the same time.

  4. Re-project the acceleration back from the missile's frame of reference to the global one, use that.

The important part here is to get the time estimate in the rough ballpark, and to not forget the missile's acceleration capabilities while doing so. For example, a better estimate for "the target is straight ahead of us and flying in our direction" would be to solve the equation ..

distance = speed x time + 1/2 x acceleration x time2

... for time (use negative speed for objects flying straight away from the missile), with the solution you're looking for using the standard quadratic formula being ...

time = (√(speed2 + 2 x acceleration x distance) - speed) / acceleration

Adding additional parameters - drag, for example - quickly turns this into differential equations with no algebraic solutions. This is why rocket science is so hard.

First of all, you should make all calculations about what acceleration to apply in the missile's frame of reference (that's where the missile is stationary and everything else moves around it, also often called "object coordinates" or "local coordinates" in game engines).

The idea then is not to aim for the target, but to aim for the place where the target will be at the estimated time of impact. So the general algorithm looks like this:

  1. Estimate how much time it will take for the missile to reach the target. If the target is flying directly at it (remember, the missile is stationary), it's as simple as calculating distance / speed, in other cases it can be more complicated. If the target can try and evade you won't be able to make a perfect estimate anyway, so it's ok to not be very precise.

  2. Assuming constant speed (1st degree estimate) or constant acceleration (2nd degree estimate) of the target, calculate where it will be at the estimated time above.

  3. Calculate acceleration which will lead to the missile to be at roughly the same spot at the same time.

  4. Re-project the acceleration back from the missile's frame of reference to the global one, use that.

First of all, you should make all calculations about what acceleration to apply in the missile's frame of reference (that's where the missile is stationary and everything else moves around it, also often called "object coordinates" or "local coordinates" in game engines, though in our case we want the velocity to be exactly zero as well).

The idea then is not to aim for the target, but to aim for the place where the target will be at the estimated time of impact. So the general algorithm looks like this:

  1. Estimate how much time it will take for the missile to reach the target. If the target is flying directly at it (remember, the missile is stationary), it can be as simple as calculating distance / speed, in other cases it can be more complicated. If the target can try and evade you won't be able to make a perfect estimate anyway, so it's ok to not be very precise.

  2. Assuming constant speed (1st degree estimate) or constant acceleration (2nd degree estimate) of the target, calculate where it will be at the estimated time above.

  3. Calculate acceleration which will lead to the missile to be at roughly the same spot at the same time.

  4. Re-project the acceleration back from the missile's frame of reference to the global one, use that.

The important part here is to get the time estimate in the rough ballpark, and to not forget the missile's acceleration capabilities while doing so. For example, a better estimate for "the target is straight ahead of us and flying in our direction" would be to solve the equation ..

distance = speed x time + 1/2 x acceleration x time2

... for time (use negative speed for objects flying straight away from the missile), with the solution you're looking for using the standard quadratic formula being ...

time = (√(speed2 + 2 x acceleration x distance) - speed) / acceleration

Adding additional parameters - drag, for example - quickly turns this into differential equations with no algebraic solutions. This is why rocket science is so hard.

Source Link
Martin Sojka
  • 5.7k
  • 31
  • 30

First of all, you should make all calculations about what acceleration to apply in the missile's frame of reference (that's where the missile is stationary and everything else moves around it, also often called "object coordinates" or "local coordinates" in game engines).

The idea then is not to aim for the target, but to aim for the place where the target will be at the estimated time of impact. So the general algorithm looks like this:

  1. Estimate how much time it will take for the missile to reach the target. If the target is flying directly at it (remember, the missile is stationary), it's as simple as calculating distance / speed, in other cases it can be more complicated. If the target can try and evade you won't be able to make a perfect estimate anyway, so it's ok to not be very precise.

  2. Assuming constant speed (1st degree estimate) or constant acceleration (2nd degree estimate) of the target, calculate where it will be at the estimated time above.

  3. Calculate acceleration which will lead to the missile to be at roughly the same spot at the same time.

  4. Re-project the acceleration back from the missile's frame of reference to the global one, use that.