Targeting your projectiles

Does your game include arrows, grenades, missiles ?
Do you wonder how you can shoot your projectile so that it hits its target ?

Well, I created a blend that facilitates your work :

[ATTACH]178963[/ATTACH]

Blend below lets you play with different options, placed on the Arrow object :

  • short: shortest/longest Arrow trajectory
    
  • v0 : initial Arrow speed
    
  • g : gravity constant
    
  • lead : should the arrow aim where the Target is or where the Target will be ?
    
  • target : target Object
    

Press Space to shoot.
Press tab to change target
Press s to swap short to long
Press l to swap lead/no lead
Press UP/DOWN to change velocity

No air friction is assumed

Tell me what you think !

EDIT : New version lets you play with the parameters during the game
Code has been very much simplified

Attachments

williamtell.blend (1.11 MB)williamtell2.blend (1.73 MB)

I can use this with archery AI to shoot arrow.
Thank you I’ll use this.

So it is calculating a deflection?
Wouldn’t it make more sense to apply that to the shooter (before shooting) rather than to the bullet (after shooting)?

What should “Align” do? I can’t see a difference when removing.

Anyway it seems to work quite well. Good work.

Edit: You should think about a better target selection. Currently it is fixed at the bullet.
Monster

  • What leading does : it calculates initial launch angles using equations found at http://en.wikipedia.org/wiki/Trajectory_of_a_projectile. Then it assumes that Target will continue using the same velocity, and use Newton’s methodto find the root to the trajectory equations.

  • In some cases, your spawner needs to shoot multiple types of projectiles. Then it’s easier if properties belong to the projectile.

  • Align makes the arrow parallel to its velocity. Effect is visible when using the longest trajectory.

This is very nice indeed!

Thanks for posting!

New version :
-lets you play with the parameters during the game
-code is now much simpler
-parameters now belong to the spawner (thank you Monster for the idea, it makes more sense now that I’ve thought about it)

Here is a new version based on your input:

  • Logic is now purely on the spawner object
  • I improved leading a bit, so it should work on faster objects. It is still heuristics based, so there are cases where it will fail miserably.

Attachments

williamtell3.blend (1.73 MB)