Precise Trajectories in Games

When you work on many different games, you inevitably encounter some problems more than once. And there was one problem that followed me around like no other: Calculating Trajectories.

I had to compute how objects will move, ahead of time, when I was working on the Construction Simulator, for placing a target marker for train turrets for End Of The Line, for a university project (as a lecturer), for predicting when an object will reach the ground, … every second game project I worked on involved some form of trajectory calculation.

Surely you would think that by now I know how to do it. And that is correct! However, I always calculated the trajectory (with drag) by doing a numerical simulation. In other words, I had a while-loop simulating some frames ahead… and I never knew how many and how long it would take for the process to finish!

I always wanted to find a better solution, but each time I told myself: “That problem seems difficult to solve and would take a long time to figure out”. Well, what else to say: I finally took the time! And indeed I found a closed formula to get rid of that loop!

And you can find all the details in the pdf below, including a reference implementation in Unity, plus some ideas for how to use the resulting equation (in combination with other algorithms).

Precise Trajectories in Games