## Sunday, January 30, 2011

### Interlocking Orbits

This week has focused on figuring out whether having planets move around the sun can be fun.

Moving planets complicate the trajectory plots in a couple of different ways. The simplest is that I need to move the planets while calculating the trajectories. The harder problems are that:
• Close to a planet, the trajectory ought to be plotted relative to that planet's local reference frame.
• When traveling long distances, the trajectory doesn't help rendezvous with moving planets since it doesn't indicate where they will be in the future.
Moving planets also complicate the construction of the solar system, because each planet needs a path that won't collide with any of the others. They may need to be spread out more from each other. To experiment, I adapted my orrery program to generate random solar systems instead of reading data about the real one.

This one really needs to be seen in motion to appreciate it. Here's a Windows executable.

This program is just generating random orbit parameters and then using brute-force searching to see if the new orbit collides with any of the existing ones. I could undoubtedly do better but it proves the basic concepts. I do some simple checks: if one orbit's minimum distance exceeds the other's maximum distance, they can't possibly collide. Otherwise, I figure their common period (m * n / gcd(m, n)) and then integrate along that period in small steps, checking the distance between the planets at each step.

The random orbits are all generated such that their periods are all integral multiples of a common base (the innermost planets' period). There are ten discrete possible periods in the current solar system, which helps me ensure that they will interlock. I'm currently using a bit of a binomial distribution on planet size and orbit eccentricity, so you'll see few eccentric orbits and few large planets.

The current problem of interest is what gameplay purpose planetary motion ought to serve. Does territorial control mean anything in a solar system? If the planets were stationary I could imagine having planetary defenses that would form a “wall” of sorts along the boundary of a controlled region. With the planets swirling around it's not nearly as clear how that would work.

There are points in time where it is definitely cheaper to go from one planet to another; this is why Mars missions are launched approximately every two years, for instance. I don't know if having a delay element like this in a game would be fun at all, though.

owen said...

Ahh nothing like a demo. Hmm I thought you were using planetary motion as a menu as opposed to a in game feature (that is what I did in my wii game: Newo Shooter). I was actually planning to show the planets passing on the horizon as you play the game but I not so sure if I will bother.

You would also have to speed up time a bit so that the delay is not too long.

What you could do is allow people to easily leave orbit if they choose, more of as a bonus than a necessity. Or you could have different things/enemies happen depending on which planet is nearest.

James McNeill said...

Hi Owen,

I'm experimenting with having the core gameplay involve flying between moving planets. It is probably gratuitous overkill but I'm giving it a shot. Using the moving planets as a menu-type thing, as you say, is a fallback position.

The main thing is to keep things from being boring while traveling.

I've been working on the large-scale game rather than the core flying. Will write more later.

owen said...

hmmmm well the concept is certainly new. You'd would have to give the player a reason though. I mean if you find a good planet then why would you fly to another one? Doesn't Spore have something like that?

Much of space is pretty empty, probably pirates? lol

Patrick said...

Your blog is the 3rd hit for me when googling "newtonian orbit ai pathfinding"

You ever have those moments when you are thinking of something and then you find out someone else has already had the idea? Kinda having one of those now. I've been working on and off (more off than on recently unfortunatly) on something that touches similar concepts to your project, a realistic system of orbiting planets and moons and the ability to fly between them in 2D. Mine is based on interplanetary trade for it's gameplay.

I'm using our own solar system as the environment with all the bodies moving in Kepler orbits, i.e. ellipses. My big hurdle is then plotting transfer orbits from one planet to another, or from a moon of one planet to another planet, etc for AI or autopilot. I'm currently looking into how solving Lambert's Problem might be useful. Previously I had been trying to search the vector space for a ships launch burn, and then seeing if the resultant orbit intercepted the targets orbit at a time when they'd both be there. But that was getting too expensive for any decent degree of accuracy over long distances.

I've been using the patched conic approximation to deal with various bodies sphere's of influence, so it's a discreet change rather than fully analogue gravity change as you change reference frame from one body to another, e.g. going from moon relative to earth relative or then to sun relative.

It makes showing an objects orbit path easy as there are no perturbations, which also makes it easier for ships to have stable orbits, and you can then predict orbit intercepts using conic interception while in the same sphere of influence. It is however crude and it would be nice to have a more realistic model with a more gradual change but that puts me back to the drawing board regards how to show the ships projected trajectory.

I've read a few of your posts so far and I look forward to giving the rest a good read.
Also really looking forward to Infamous 2

I reckon I've rambled enough.

Great blog.

James McNeill said...

Patrick,

Thanks for the compliments. I've neglected this blog for the last six months due to work; it's been rather more than a day job for a while. I aim to get back to it now.

Your trading game sounds like a good project. What are your thoughts regarding the trade model for your game? Is it buy low, sell high, and trade up to successively bigger ships as you go? That's kind of the ancient Elite/Frontier model.

It seems to me like a big part of actual trading probably involves negotiating contracts for serving regular routes for particular customers. This doesn't fit well with the Elite style of game where you're piloting a single ship.

Lambert's problem is for the "bang bang" trajectories where the rocket fires instantaneously at the start to set itself on a ballistic trajectory, coasts for a long time, and then fires again when it arrives. This is an adequate model for current propulsion systems. If you are using a solar sail, or some other continuous-thrust engine, though, it doesn't work. The travel times tend to be crazy long, too; typically the planets you're transferring between will rotate through a large fraction of their orbits (if you're aiming for minimum fuel trajectories, that is). After playing around with that a bit I decided it would be too slow of a time scale to make sense for my game.

For trip planning with ballistic trajectories, you could just solve Lambert's problem for a variety of launch times and arrival times to see which trips are feasible (in terms of the velocity change required). It's not that expensive to solve.

If you have all your planets set up in resonant orbits (like what I was doing with my interlocking orbits) then you could pre-solve a timetable of potential trips between the planets. (It'd be like a bus schedule.) If you're basing it on the real solar system that's not possible, though.

Patrick said...

I invision it as the player is the head of a small company, starting with one ship and then through either buy low/sell high, or through contract work for other firms, earning the funds to upgrade that ship, trade up or expand your fleet to more ships. The idea is similar to a game I saw years ago that was based on cargo ships at sea, you took on contracts, bought bigger/more ships, had to manually dock them when the arrived at ports, can't for the life of me remember the name of it though. I've always been a fan of games like the X series, Freelancer, Independance War, but I wanted to see what a similar game in realistic environment with objects moving in orbits might be like, instead of solar systems that lack scale and using jumpdrives to move from essentially one big room to another.

Some of the core ideas I wanted to work into the game were it being based in our own solar system, using semi-realistic propulsion and the possible effects of a dynamic, long cycle changing system they both cause. Buying low on earth and selling high on mars might be profitable for a while, but once mars is occluded by the sun then profit margins might be tighter and you might need to find a better route, it makes trade routes changable, which I like the idea of.

Regards propulsion technology, I wasn't planning anything as slow as current technology, but still "bang bang" systems, more like nuclear pulse engines, or fusion torch style devices. A certain amount of inspiration for the technology level came from an RPG setting called Transhuman Space. I'm invisioning ships which have 60 to 100 km/s total delta-V, can do a Earth-Mars trip in around a month and Jupiter is a few months, depending on alignment of the planets.

Any timestep that is appropriate for a lunar transfer is going to be wrong for a jovian one, and vice versa, but as I'm not moving the objects in my simulation by numerical methods, but rather by determining their position based on ephemeris I hope to be able to use variable timescales, that will help player experience by having time go quicker during longer trips, but it might put extra pressure on AI.

Once I make some time I'll implement a lambert solver and give it a test. Still going to need a nice way to patch together the different body relative trajectories. I imagine I'll have it solve the highest level one first, eg Earth to Mars, that will give a target point to leave Earth's sphere of influnce and begin the heliocentric transfer at, then I can plot the trajectory to get the ship to that starting point. Or something like that.

With the speeds the ships are liable to be going a lot of the time trajectories will be close to straight lines, and the temptation to approximate them to that is high at times, but I'd much rather not. I've an awful habit of choosing challenging goals, but they are the most fun goals.

Mario Guerra said...

This post is old, but I thought it'll be good to share. Maybe the ships and cargo (at sea) game Patrick speaks of can be "Ports of Call"?

Patrick said...

Wow, I was sure I was never going to come across the name of that game. That's exactly it.

Thanks