• Create Account

## Homing rockets

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

12 replies to this topic

### #1_Flecko  Members

Posted 15 July 2005 - 08:46 AM

I didn't think it would be too hard, but I'm having some difficulty getting homing rockets to work in my 2D game. I tried having them rotate towards whatever their selected target was and then accelerate in the direction they were rotated in, but what tends to happen is that they'll just circle their targets - it's like centripetal force, since they always rotate to face their targets unless they come at them straight on, their acceleration will be tangent to their velocity. Does anyone have a good algorithm for rocket homing they wouldn't mind sharing?

### #2Anonymous Poster_Anonymous Poster_*  Guests

Posted 15 July 2005 - 09:21 AM

Quote:
 acceleration will be tangent to their velocity

I think you answered your own question there :)

Instead of accelerating towards your target, save out your velocity and modify it directly by some homing factor.

### #3bytecoder  Members

Posted 15 July 2005 - 09:26 AM

Over-rotate by about 15 degrees--I believe this is how homing missiles in real life work.

### #4_Flecko  Members

Posted 15 July 2005 - 06:23 PM

Ok, what I ended up getting to work is sort of a combination of your two ideas. Each frame the rocket takes two vectors, the negative of its current unit velocity and the unit vector in the direction of its target. It multiplies each by some factor and combines them to get another unit vector, which it multiplies by its acceleration rate and uses to change the velocity. So, it's not really based on rotation, but it does work by selecting a vector that aims to the side of its target.

### #5markr  Members

Posted 16 July 2005 - 12:09 AM

This is not a problem with the missile not anticipating the target's movement - rather, it's a problem that the target is inside the missile's turning circle, so it just orbits.

The missile should be able to determine whether the target is inside its turning circle. If so, it should fly in a straight line (or possibly even turn in the opposite direction) until the target is outside its turning circle. Then it can resume normal homing behaviour, which will result in it flying straight, turning around and coming back bang onto the target.

For added security, make the circle you test for slightly bigger than the missile's actual turning circle.

Here's a picture

Mark

### #6Anonymous Poster_Anonymous Poster_*  Guests

Posted 16 July 2005 - 12:26 AM

Rotate to aim at a target point which is a projection of the targets current movement vector (project X time periods ahead with X getting smaller by current distance between missile and target divided by some velocity).

It wont solve all the endcases but can make your intercept course more efficient.

Also limiting the maximum velocity of the missile can make your turn radius (during terminate maneuvering) smaller. It should still be fast enough to close with the target, but also be somewhat limited when close to the target.

### #7ajas95  Members

Posted 16 July 2005 - 07:12 AM

Your problem is that the missile is always trying to fly at top speed. If it slowed down, it could turn in a tighter circle and hit the target.

Personally, I would code it like:

struct missile{    vec3  pos;    vec3  velocity;    vec3  accel;    float spring_const;  // = 0.3f or so.    float min_speed;    float max_speed;     // etc.};void missile::home_on_target(const vec3& target, float timestep){    // ideally, our velocity will be directly at the target, at top speed.    vec3 to_target = (target - pos).set_length(max_speed / timestep);    // adjust velocity.    damp_spring<vec3>(velocity, to_target, accel, spring_const, timestep);    // don't set min_speed too high...    clamp(velocity, min_speed, max_speed);    pos += velocity * timestep;    // done!}

where "damp_spring" is the function I define here.

### #8vNistelrooy  Members

Posted 16 July 2005 - 07:34 AM

Quote:
 Original post by bytecoderOver-rotate by about 15 degrees--I believe this is how homing missiles in real life work.

No, in real life radar-guided or heat-seaking missile usually fly towards the place where the missile expects to find the target when the missile reaches it.

target------>BOOM             /           /         /       /     /missile

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

### #9haphazardlynamed  Members

Posted 16 July 2005 - 05:56 PM

Depends on the missle
some are cheaper than others

### #10Fingers_  Members

Posted 17 July 2005 - 06:54 PM

If you want a "newtonian" missile that only uses forward thrust, simply trying to point at the target isn't enough. What you need to do is determine the direction/velocity that you need in order to hit, then subtract the current velocity from that to get the direction you need to apply force in. Point the missile in this direction and apply thrust. This means the missile might point 90 degrees to the side when performing a turn, for example. In an orbiting situation it may even turn backwards to break the orbit.

### #11Horatius83  Members

Posted 17 July 2005 - 07:30 PM

Sidewinder missiles will over-correct by 15 degrees, the heat sensors (I think it's an array of like 128 by 128, lower on earlier versions) pick up the heat as the missile rotates, and kind of zig-zag up to the target. You might try to have a 30 degree arc divided into two, then have the missile either slightly up, or down at certain intervals until that zone loses contact. Like the upper zone causes the missile to steer upward, then loses contact, so the missile then thrusts down until the lower zone loses contact (and explodes if both zones lose contact, meaning the missile has overshot the target, or is beside the target)

Check out http://www.howstuffworks.com it's got all kinds stuff about sidewinder missiles and what-not

Posted 17 July 2005 - 07:58 PM

Quote:
 Seek attempts to steer a vehicle so that it moves toward the goal. This is in contrast to a central force (such as gravity) which causes an inward acceleration and so leads to orbital motion.

Tip: Look into "Seek And Flee", "Pursue and Evade", "Obstacle avoidance" and finally "Combining behaviours" in his gdc paper from 99. Better yet, read the text in the paper and watch the animations on the homepage(the text in the paper is easier to understand).
This will give you a great missile that homes to where the character is going to be and avoids obstacles :)

### #13Delfi  Members

Posted 17 July 2005 - 10:56 PM

i got this in this same forum while ago.. i never tested it but it should work i think, tell me if it does.

// gamedev - homing missles:

//starting position
//bullet speed
//target position
//target velocity
//Vector2D LeadTarget( Vector2D sp, float bs, Vector2D tp, Vector2D tv )
{
Vector2D D = tp - sp;
float E = D.Dot( D );
float F = 2 * tv.Dot( D );
float G = bs * bs - tv.Dot( tv );
float t = ( F + sqrt( F * F + 4 * G * E) ) / ( G * 2 );

return D / t + tv;
}

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.