Jump to content
  • Advertisement
Xaerix

Lead Moving Target with Moving Shooter

Recommended Posts

Hey guys, been looking at this article in the hopes of being able to implement a way of an AI helicopter with a turret to shoot at any nearby enemys within a certain radius. Up to now I seem to be having no luck.

I'm wanting to know how I'd adjust this formula to accomdate a Moving shooter with a constant velocity.

To Clarify I know:

Shooters Position, Shooters Constant Velocity, Shooters Projectile Speed

Targets Position, Targets Constant Velocity.

Also in order to prevent bullets fired forwards whilst moving forwards being too slow, the Directional Vector from this target leading has the current velocity of the shooter added onto it before being multiplied by the bullets speed.

 

Share this post


Link to post
Share on other sites
Advertisement

If you choose a frame of reference in which both target and shooter are moving at constant speeds vt and vs, follow the calculations in the article pretending vt is vt-vs and vs is 0. Times are unaffected, while if you want the projectile velocity you need to add back vs.

Share this post


Link to post
Share on other sites

I once had a similar question for an AI enemy controller that shot a cannonball at the player's ship. It turns out the equations can get extraordinarily complicated, very fast. I would strongly recommend coming up with a different approach than one that is fully deterministic. For example, having the AI 'guess' how far to lead a shot and then adjust based on how far it missed using a physics engine for detection. This has the added benefit of not having to derive the perfect targeting equation only to then add a "fudge factor" for the sake of difficulty and realism.

Share this post


Link to post
Share on other sites
2 hours ago, cjmarsh said:

I once had a similar question for an AI enemy controller that shot a cannonball at the player's ship. It turns out the equations can get extraordinarily complicated, very fast. I would strongly recommend coming up with a different approach than one that is fully deterministic. For example, having the AI 'guess' how far to lead a shot and then adjust based on how far it missed using a physics engine for detection. This has the added benefit of not having to derive the perfect targeting equation only to then add a "fudge factor" for the sake of difficulty and realism.

 

It's not that hard. You write down an equation that says "at the time t when the hit happens, the target will be at a position P(t) such that the time it takes a projectile to get there is t." Any positive solution of the equation will do. If everyone is moving at a constant velocity, the equation is quadratic. With constant acceleration (e.g., if gravity is involved), the equation is quartic. In any case, as long as every function involved is smooth, you can use Newton-Raphson to find solutions with very good precision.

 

 

Share this post


Link to post
Share on other sites
35 minutes ago, alvaro said:

 

It's not that hard. You write down an equation that says "at the time t when the hit happens, the target will be at a position P(t) such that the time it takes a projectile to get there is t." Any positive solution of the equation will do. If everyone is moving at a constant velocity, the equation is quadratic. With constant acceleration (e.g., if gravity is involved), the equation is quartic. In any case, as long as every function involved is smooth, you can use Newton-Raphson to find solutions with very good precision.

 

 

I didn't mean to imply that it was hard, only that it was excessively complicated. KISS is an effective rule for game development and should be adhered to whenever possible, in my opinion. In addition, the problem with creating deterministic solutions is that you need a lot of information about the environment available in order for objects to solve the problem. The issue with this approach is that it makes objects tightly linked rather than the more ideal version of them being flexible, encapsulated logic as loosely linked as possible. Basically, I mean to say that just because you can solve the problem with an equation doesn't mean that you should.

Share this post


Link to post
Share on other sites
4 hours ago, cjmarsh said:

Basically, I mean to say that just because you can solve the problem with an equation doesn't mean that you should.

Sometimes you should because it's appropriate for the game.

If the "shooter" is a grenade-throwing killbot attacking trespassers, what should it do if not measuring target speed and velocity, computing an exact solution and lobbing the grenade exactly there? It's not only realistic for an AI with excessive computational capabilities and motor control accuracy, but transparent for the player and interesting to interact with (player controlled trespassers need to take cover or to change velocity while the grenade is in the air).

Other kinds of shooter, like artillery in trench warfare, might be more realistic if they guess iteratively, but even in that case if they are remotely competent the exact computation, maybe perturbed with inaccurate position and velocity measurements, is needed as a starting point.

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!