Having enemies throw grenades or launch projectiles in games often requires some form of trajectory planning in order to find the best launch moment, speed and angle. When trying to take drag and wind into account as well, this process quickly becomes complex and inefficient.
The research paper below proposes a novel and practical approximation of 2D and 3D trajectories with drag and wind, which allows for very efficient planning.
“Analytical Ballistic Trajectories with Approximately Linear Drag”, Giliam J. P. de Carpentier, International Journal of Computer Games Technology, vol. 2014, Article ID 463489, 13 pages, 2014. doi:10.1155/2014/463489. [PDF] [Additional resources]
This paper includes formulas and code snippets that can be used to easily calculate the initial velocity to hit any target given the initial position, the target position, the gravity, wind and drag constants, and
- the time to target, or
- another position to pass through (or to shoot exactly over an obstacle, for example), or
- the top height, or
- the launch slope, or
- the slope to hit the target at, or
- the arc height, or
- the exact launch speed, or
- with the least amount of speed possible (the way humans typically like to do it)
To demonstrate all this in practice, I've made a free and open-source demo project for Unity3D 3.5 and up. It exposes all the above ways of plannings through composable planner behaviours attached to automatic turrets that can shoot at static targets, moving targets, and (experimentally) even over polygonal obstacles. The source is available as the BitBucket GIT project https://bitbucket.org/gdecarpentier/ballistictrajectoriesunitydemo. You can run it in your web browser using the Web Player [Open] or download the standalone Windows version [ZIP].