Space Sim, How to procegerly generate a Galaxy map?

I am making space games both 2d and 3d how would you procedurally generate a galaxy?

There are many resources for procedural generation of everything, from names to galaxies. A quick web search reveals many of them.
http://martindevans.me/game-development/2016/01/14/Procedural-Generation-For-Dummies-Galaxies/
Elite (1984) Elite, created by Ian Bell and David Braben and released on the Acorn BBC Micro, defined a generation of British games and started a history of procedural generation. Elite is a game that...
https://www.google.com.au/search?q=procedural+galaxy+generation+algorithm

I’ve actually done 2D procedural generation of a galaxy map. It’s quite easy.

First, you decide an origin point of the map (in my case, (0,0) would be the origin point). This is the centre of the galaxy and what everything orbits around.

Spawn a planet - or a sun, or a moon, whatever you’d like - at that origin point. This is what everything’s going to orbit around so obviously you want something that looks like it has a big gravitational pull.

Then, decide how many planets/etc that you want to spawn. For each one, decide its mass, how far away from the origin point you want it to be, and generate a floating-point number between 0 and 360. Now’s the time to generate all the other info you’ll want to add to the planet (name, etc). The important things are that floating point number between 0 and 360, and the distance from the origin.

Using those values and the location of the origin, you can run them through a mathematical formula to calculate a Vector2 of where the planet should be spawned on the map. This’ll decide the initial position (in the orbit) of the planet as well as how far away from the centre of the galaxy it’ll be situated.

This’ll get you the initial galaxy map. Bonus points if you can get the planets to move as if they were orbiting around the origin.

You can do this by increasing the “degrees” representing where the planet is in its orbit by a constant value (possibly 0.01F?) and when it goes above exactly 360, wrap back to 0 and keep going. Each time the orbit position value changes, do the same thing you did when first generating the planet and you’ll get the new position for the planet.

If you want the planets to orbit in the opposite direction, it’s the same thing - just decreasing the orbit position value by a constant value, and wrapping back to 360 when it reaches 0.

Even more bonus points if you can tweak the way the planets orbit based on things like their mass, distance from origin, shape, etc. I can’t tell you how to do that. I don’t know how.

Also for that “position from distance and degrees” formula… have a look at this StackOverflow post.

1 Like