Skip to main content
gamedev.net
🔒 Locked

Calculating intercept angle

Started by Argus Nov 4, 2002 at 3:03 PM 6 replies 4.3k views
Original Post
Argus
Argus
(this is a cross-post from the math and physics forum - haven''t received any definitive answers from there yet so thought I''d try here. Delete if necessary.) I was wondering whether anyone has a non-iterative formula for finding the angle one should fire a constant velocity projectile in order to hit another constant velocity projectile (in 2d)? If there is definitely no such formula, what''s the best way to write an iterative one? And yes I''ve tried google numerous times, and search on these forums is still broken. Any help would be much appreciated.
Waverider
Waverider
I can't provide any real formulas at this time, but here's how it works.

You know that the point you're going to fire at is somewhere along the straight-line trajectory of the target object.

If you know the velocity of your projectile, and the velocity of the target object, then you just solve for the point on the target's path such that...

t0 = target's original position
w0 = weapon's original position
p = point to fire at

| p - t0 | / | p - w0 | = velocity of target / velocity of projectile

In short, the ratio of the velocities of the two objects must equal the ratio of the distances the projectile and target must travel to meet at the same point.

p in this case is t0 + vt*k, where vt is the velocity of the target and k is the constant you will solve for in the equation.

Hopefully that gets you started. Express the magnitudes above as calculations on the vector components, and it should evaluate to a quadratic that has one, two, or no solutions for k.

[edited by - Waverider on November 4, 2002 4:42:48 PM]
It's not what you're taught, it's what you learn.
Argus
Argus
Thanks guys - I did run into some problems though :

Wave - From my limited knowledge of mathematics, the subtraction of one point from another eg "p - t0", is a vector. I''m not sure what the | | operator does to a vector though, nor how one divides a vector by a vector if the result of the | | operator is a vector itself.

Also, are you suggesting that I substitute t0 + vtarget*k for p, and then algebraically manipulate to get k on one side?

AP - Thanks for all the code, it looks like it might be what I need, but I had a problem where the angle doesn''t seem to be on an intercept heading, but tending more toward the initial position of the target ie lagging behind a lot.

I took the liberty of altering quadrant 2 to return (PI - angle), and quadrant 4 to return (2*PI - angle), although I did also try with the initial expressions.

Can you see anything in your code that might be the cause of the problem?
Waverider
Waverider
| | means take the magnitude of the vector which results in a scalar. I would square both sides of the equation to get rid of the square root portion, though.

And yes, substitute p and get k by itself.

Good luck!
It's not what you're taught, it's what you learn.
Argus
Argus
Actually I think the problem may be with my estimation of the target heading rather than with your intercept code. Thanks greatly for all the code and if I can help you out some time let me know (would be easier if you weren''t anonymous).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.