AutoAim: calculating the aim-ahead so you don't have to...

Hi folks,
I’m making an asset that calculates the direction you need to aim in if you want to hit a moving target. This is useful in games where you need the AI to shoot at a moving target and you’ve not got instantaneous bullets.

Here’s a link to a webplayer demo of AutoAim.

In the above demo both the targets and bullets are constant velocity, unaffected by gravity. However I also have code to solve the problem where gravity is involved, and another solver that predicts the movement of the target by approximating the movement of the target as a curve and aiming accordingly. I found this useful for targeting the player in the biplane game I was writing.

The code is extensible, so if you have another kind of movement that isn’t supported, you can insert your own prediction class and the iterative solver can use it.

On the other hand, if you’re not a coder at all, I’m trying to add enough little helper scripts so that you can get something working just by dragging a dropping scripts onto your objects in the editor.

I’m interested to hear any comments or suggestions.

Cheers,

Tim

829580--30918--$autoaim1.jpg

This is a very common problem indeed, so here are a couple suggestions (actually, things you have to answer for the dev) to make it really interesting and useful:

  • I want the projectiles to be controlled by physics, can I simply give your script my current target’s position and direction and get back what’s the force I have to apply to my projectile to hit it?
  • How can I add an “accuracy” setting to that turret? Your demo planes are always being hit. Lowering accuracy would involve a missing chance (in % of projectiles fired) and a missing radius, so that it actually aims something around a radius of the actual target. Great for artillery shells and such.
  • Suppose the turret rotation is limited (and it generally is) can I get all the relevant values considering my current rotation and the ideal firing rotation to actually hit the target?
  • Suppose my projectile is a self-propelled missile with some homing capability, but it could only turn a maximum amount of degree per second. Can I make the “ideal firing rotation” account for that homing angle? Ideal for slower rotating turrets and fast-rotation missiles.

Those are the most common design requests I can think of, so if you can attend to them in a user-friendly fashion I think you’d have a nice product. Good luck :slight_smile:

Thanks, Maddox.

Currently you provide the aimer with the initial speed of the projectile and the script gives you a Vector3 direction that you have to fire the bullet in. You can use that vector (multiplied by the speed and mass of the projectile) as a force to start the bullet moving at the appropriate velocity.

Yes, I was planning to add an accuracy value to the helper scripts. I didn’t add it to the demo because nobody’s going to be impressed by an aiming script that misses :smile: . It’ll take a little thinking through as the mis-aiming needs to look plausible.

The script just gives you the ideal firing direction, given your projectile’s launch speed. I’m not sure what you mean by ‘the relevant values’, but you could just hold off firing until the dot product of ideal firing direction and your turret’s forward vector is very close to 1.

That’s probably a bit specific to be included in the asset, but if you can write a bit of code that will predict the position of your projectile at time t given it’s starting parameters you could plug it in to the system.

Thanks for your feedback!

Cheers,

Tim

Bother. I’ve just realised that I should have put this in the ‘Work in Progress’ forum. Sorry! Feel free to move it…