Sign in to follow this  

Programming a Simple Auto-Tracking Missile

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by CuppoJava
The 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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by jRaskell
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.

True. Actually, in many cases, a significant portion of the targets of a complex piece of ordinance -- such as a guided missile -- which survive do so because the missile fails. The failure rate for ordinance at least used to be very high, meaning that if you survived being targeted by a missile or hit with a bomb it was because the thing didn't go off, its guidance failed, or something else went wrong. I don't know if you would want to model that in a computer game though. I think it might just frustrate the player.

Share this post


Link to post
Share on other sites
Okay,
I got the leading part working. Thanks for all the help guys. Here's my final equation for those of you that may want it.

//p is a pointer to the plane
//p.vx, p.vy, p.x, p.y = plane's velocity and position
//x, y = missile's current location
//v = missile's top speed.

float A = (p.vx*p.vx + p.vy*p.vy - v*v);
float B = 2*(((p.x-x)*p.vx + (p.y-y)*p.vy));
float C = (p.x-x)*(p.x-x) + (p.y-y)*(p.y-y);

//solve quadratic equation

float t = B*B - 4*A*C;
t = (float)Math.sqrt(t);

t = (-B+t)/(2*A); //Solution 1 OR
t = (-B-t)/(2*A); //Solution 2

tx = p.x + p.vx*t; //intersection point.
ty = p.y + p.vy*t;


Care has to be taken when doing the square root. If there is no real solution the program will crash if you try to take the square-root.

Again thx for the help guys.

I was also wondering if anyone has experience dealing with acceleration. I'm finding it pretty hard to program.

eg. Consider one dimension.
My Plane is at position 5
It currently has a velocity of 3

My Plane wants to get to position 150
It can apply an acceleration of 2 in either direction to get there.

How do I program my plane to get to the position in the shortest amount of time?

Share this post


Link to post
Share on other sites
If you keep track of the missle's recent positions, you can approximate the missle's future positions with a taylor series [http://mathworld.wolfram.com/TaylorSeries.html]. It's probably harder to implement than you are looking to do, but I thought I'd mention it because it seems like the most elegant solution to me. The gist of it is if you have the last three positions, you can calculate the average velocity and the average acceleration (1st and 2nd derivatives of position) over those steps, and use those calculated averages to project a future position in time. More previous positions means more accurate predictions, assuming the pilot stays with the same trend of motion (say, linearly increasing acceleration which might arise from a gradual increase in thrust).

The way a pilot 'jinks' the missle is by unpredictably chanigng his flight path, rendering past time steps irrelevant and causing the prediction to be off. For realism, you'd probably want to sample positions every half second or so- any quicker (say, every frame) would allow the approximation to get back its accuracy in a few ms. The half second delay is analogous to a targetting human's delayed reflexes.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this