Many years ago I worked on a space-flight game. The idea was to create something like Elite, but with a little more cartoony graphics and a strictly 2d flight model.<p>The physics behind it was fairly accurately modeled; you can ignore the 3rd dimension for a lot of orbital mechanics. The scales were unrealistic, the gravitational constant was tweaked for more fun, but the actual Newtonian formulas were correct. Orbits behaved properly and so forth.<p>The hard problem was adding NPC space ships. I had simple requirements: Have a spaceship at location X and velocity vector Y, accelerate and move to location X2, slowing to a stop as they reached it, taking into account intervening gravitational wells. I naively thought that was a simple solved problem that I could find the answer to with a little googling.<p>Well, it's not, at least at my level of mathematical knowledge.<p>I made it work, though. Not by exactly solving a god-like deterministic formula, as Newton himself would have, but by tweaking an algorithm I found from the early days of guided missiles.<p>It's an interesting algorithm. It basically worked this way: Ping your target, and figure out by what angle you're going to miss it at your current heading. Point your rocket at double that angle delta. So, if you're going to miss the target by 10 degrees to the left at your current heading, point your rocket 10 degrees to the right of your target. Continue thrusting.<p>Repeat, many times a second, and the angle you're missing by becomes smaller and smaller, until BANG. And, because it's really a fly-by-the-seat-of-your-pants heuristic, if gravity is pulling you off course, the correction automatically increases.<p>I had to do a little addition, like chopping the trajectory into chunks if there was a major gravitational body in the way, because the algorithm broke if you got too close to a planet.<p>Oh, and guided missiles accelerate until they hit. I had to have ships accelerate to the halfway point, turn around, and then decelerate until they stopped at the destination. It was fairly simple to find the point at which they would need to begin decelerating in order to hit zero speed at their destination. The fun part is that the guided missile algorithm still worked, but you just had to change it so you maneuvered based on the point exactly opposite of the target.<p>The takeaway is that the exact 'correct' solution to the problem was hard; practically unsolvable, at my expertise. But it was easily managed by implementing a few simple behaviors into the NPC ships, which were really not very different than how a player with a little learned intuition would pilot. As a bonus, I think they were more believable that way. They flew more naturally.<p>Someday I need to finish that game.