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/

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