# proceduraly generated galaxy

So i was watching “How Does No Man’s Sky Actually Work? - Reality Check” and i decided to give it a shot since I have been wanting to do a giant galaxy in a game yet i dont know how to save data and im sure it would take a lot of memory. So what i was basicaly going for was not a completely proceduraly generated system but more like deciding the place to spawn a prefab and its characteristics like being able to tell the game to generate a prefab of a sun when i get somewere, maybe give that sun a particular size and color according to diferent factors like (and im no astrologist, im just guessing here) proximity to debree and gas tipe or something, also have some planets orbiting and maby have some with rings or several moons and stuff, you get my point.

so the paroach i had was to take the position and with it use calculations to tell the game where to spawn “x” prefab, but that didn`t get me anywhere.

my question to you guys is how would you go about proceduraly generating a galaxy?

thank you all,
-thenachotech

I’m no astrologist either so I’m not sure how galaxies work; but lets say each one has a sun. Start by spawning a sun and a random amount of planets around it with random distances from the sun. Do this increasingly so you can make sure 2 planets can’t collide. You can then spawn moons/asteroids around the planets the same was as you did with planets and the suns, again making sure that they can’t collide. You can even make moons around moons (just use a recursive method).

Next comes the spawning of multiple galaxies. Move from the first galaxy to a random x,y,z away. Making sure the distances are large enough. Then from this point start spawning again from the start and with each planet, make sure they can’t collide with their sun and the other galaxies. You can easily get the range between the sun and the most outward planet to calculate this.

From here you can keep going with the current galaxy or start spawning from both suns. The last method is recursive as well.

Be careful not to have an endless loop while spawning.
Also keep checking every time if planets/suns can’t collide and that they are spread far enough.
You can even use overlap spheres to test this if you wanted.

Lastly you can add things like asteroids or meteoroids. Spawning them at a random place that doesn’t collide.
Distance(Sun, Planet) + Planet.x /2 (upper collide value)
Distance(Sun, Planet) - Planet.x /2 (lower collide value)

If you check that newly spawned things don’t fall between those numbers you’re ok.

Ricewind’s answer is pretty good already, but I have a few points that might help.

The ways to do it mostly depends on a few things.
For example, do you want the planets/moons/stars to rotate during the course of the game?
Do you want the rotation to be fixed or calculated with physical laws.
Do you want to respect the real world’s laws (weight, distances, speed, size…)?
Do you want the orbits circular?
Do you want the orbits to all be polar?
Is it 2D or 3D?

Having made a prototype on XNA during my last year as a student, I had to answer all of these too, and it all comes down to how much time and computing power you want to allocate to this.

If you just want to make a galaxy, you can follow the advices RiceWind gave you, and add a few things like colours for your stars and planets.

What I would be looking for is a function that can generate noise that can be converted into a galaxy. Perlin noise might do the job, with a bit of refinement. There are other pseudorandom functions that exist. The main property you are after is that if you pass a set of coordinates to the function it will always return the same result.

This way you have no need to store the actual data. You can simply query your noise function and generate the local galaxy region on the fly as the player passes through it.

To complete this you need a deterministic (ie no calls to Random) method to generate local space given a small number of parameters.