# Programming a Simple Auto-Tracking Missile

This topic is 4990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm programming a jet game and I wanted to have auto-tracking missiles. I worked out some tracking code by myself but it looks too unrealistic and is either too bad (can't hit anything) or, when I adjust the parameters, too good and is inescapable. Does anyone have a few good ideas or links on how this is done? Currently I'm doing it like this: ------------------------------------------------- When tracking a plane Calculate the relative angle between the plane and the missile Turn the missile toward the plane. There is a max turning-velocity so that the missile can't make abrupt turns. If the relative angle between the missile and the plane is too big then TARGET LOST. ------------------------------------------------- The problem is that the missile does not know how to lead the target, and so misses all the time, unless I turn the max_turning_velocity all the way up, and then it just looks ridiculous. Thanks for your input -Cuppo

##### Share on other sites
Hmmm, I've never programmed one myself, but some ideas come to mind. I mean, couldn't you move the 'center' of the plane outfront, so it fakes leading? And one Idea(again, never tried it myself, but it should work). Instead of having a max turn angle, find the angle, and then multiply it by an Accuracy %. The higher it's accuracy(actually, really agility) the more it can turn.

Just some thoughts.

##### Share on other sites
surprising how often this gets asked :)

Teach your missile to lead the target? Estimate time to target. Project target forwards by that amount of time at current velocity. Aim at projected target position.

##### Share on other sites
real Sidewinder missles are not very smart
they dont calculate target velocity or lead time or anything like that

they simply oversteer
if the target is 5degrees to the left, they aim (5*x)degrees left
where x is some adjustable oversteering amount
mess around with it till it gets what you want

oh yeah
and you might want to consider using real physics, instead of animation 'turn radius' type stuff
that should keep it looking real, and also give more margin for the player's flight envelope to outperform the missile...so it doesnt get unescapable

p.s. missles run out of fuel

##### Share on other sites
In reality, guided missiles are basically very tough to dodge. Smaller, faster, and more maneuverable than the jets they're targeting. The two effective defenses against missiles are countermeasures and stealth design. I don't think stealth design is really applicable here, so that leaves countermeasures.

Implement some chaffe countermeasures that the missiles will lock onto, giving you time to maneuver outside it's range of detection. The chaffe doesn't neutralize the missile though, so if you're still within it's range of detection when it passes through the chaffe, it'll reacquire and you're still sol.

Alternatively, try spending some more time playing with not only the missiles turning ability, but it's range of detection. I see no reason why you shouldn't be able to find a happy medium somewhere in there that at least makes the missiles something you have to pay attention to. You may also want to play with the missile speed as well. Plenty of variables available to tweak in search of some balance.

##### Share on other sites
Thx for all the great answers guys.
I am going to implement a chafe or flare system later, but first I want to get the missile looking right. But yeah, I realize that those two aspects will be an important part in the balancing.

The idea of real physics is appealing, but "real" is still just relative, I'm guessing your talking of using acceleration instead of velocity, as absolute real physics would mean fluid dynamics and all that.

I'm thinking that I can use a theta_acceleration variable. Where theta_acceleration is how rapidly the rate of change of the angle may change. ( anybody get that...)

Can anyone offer some tips on that?

PS: On sidewinder missiles: Is it true that they just oversteer? That would make programming it a lot easier, but is it accurate enough?

##### Share on other sites
I found the Sidewinder info here:
http://people.howstuffworks.com/sidewinder6.htm
fun site
If you wanted to make an even more accurate missle, maybe a full PID or PD controller might work.
as they describe it, Sidewinder uses P-proportional control
PID stands for Proportional, Integral, Derivative, basically means considering things like velocity in addition to just direction

##### Share on other sites
Quote:
 Original post by CuppoJavaThe problem is that the missile does not know how to lead the target

Determine the current direction of the plane ( current position - position at previous 'tick' ) then use it to estimate the plane's position during the next 'tick' ( current position + direction ) and aim your missile at that spot instead of the plane's current position? It's obviously going to be inaccurate as sudden changes of direction and/or speed will throw the missile off... but perhaps in this particular situation this is a good thing as it gives the player a chance to outmaneuver the missile ^^;;

##### Share on other sites
If it a smart missile, them make it 'smart' and assign a pointer to its target to the missile. That way, no matter how the simulation goes, the missile will always know where to go. After that:

a. Find the target current position
b. Find the angle between missile_direction and vplane - vmissile vectors.
c. Turn the missile and appropiate angle for this dTime. This step is tricky as you should apply some physics. You have your position, direction, current speed, mass of the missile and elapsed time. Knowing the angle, you should be able to compute your final position. You may simplify your formula if you discard mass and tangencial forces. Your direction should become an tangent of your trajectory.

I guess that should be enough.

Luck!
Guimo

##### Share on other sites
Once upon a time, I worked out the math behind leading a target. You can do it too. The basic problem: Given a stationary gun with known projectile velocity and a moving target with known position and velocity, what's the unit vector that the gun should fire along? It's a bunch of linear algebra, which you can work out to an explicit solution if you sit down at it with a pad of paper and a pencil. When you do work that out, just use that vector at each timestep to set your direction. Voila.

Want acceleration of the target included in the calculation? That's more math, and involves finding roots of 4-th order polynomials. I never worked it out, and you're probably better off using numerical methods.

There's an iterative technique out there also. Each timestep, you run a few little simulations: You try aiming straight at the plane, and see if you hit it. If you don't, see where the plane is when your missle hits where the plane would have been if it had stood still. Then use that position as the plane's position for the next iteration. Run that loop a dozen times and by the end you've got a decent approximation - or so I've been told.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 12
• ### Forum Statistics

• Total Topics
634117
• Total Posts
3015601
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!