• Advertisement
Sign in to follow this  

Homing rockets

This topic is 4569 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

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?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Over-rotate by about 15 degrees--I believe this is how homing missiles in real life work.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster


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.

Share this post


Link to post
Share on other sites
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.

Share this post


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Linky

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 :)

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement