Planning ballistic trajectories with air resistance for games

March 26, 2015 Math, Physics
Ballistic trajectories

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)

Unity3D implementation

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].

Screenshot from the Unity3d demo project

Screenshot from the Unity3d demo project

 

Additional resources

  • The paper's two C++ algorithms but with improved spacing and color coding [PDF]
  • The paper's Figure 4 as an animated GIF [GIF]

Comments (5)

Craz3d_Banana
February 2, 2014

You did a really good job on the paper. Every scenario that one would need is clearly explained and accompanied with source code. Best of all, its written in C++.

My only dislike is probably due to my opinion so take it how every you see fit. But, when reading the source code in the paper is a little difficult due to there not being any spacing between comments and code.

Giliam
February 2, 2014

Thanks! Spacing and color coding in the algorithms sadly got 'lost in translation' in the publishing process. I've added a link in the Additional Resources to a PDF containing the same code in the much more readable original layout for your convenience.

Craz3d_Banana
February 3, 2014

Thank you for releasing an easier to read version. Best of luck to all your future endeavors! ^_^

Thilina
June 3, 2014

Great work! I'm also working on a similar project in Unity3D and I would really appreciate if you could share the project.

Giliam
March 26, 2015

Hi, Thilina (and others). It took me a bit longer than expected, but the Unity3D project is finally publicly available. Enjoy.

Leave a comment