2d galaxy, random generation

Can someone tell me how to generate a galaxy with constellations (sectors with stars). On the similarity of the game Space Rangers 2. As I understand it, there is a generation of star systems (points) within the boundaries of the polygon according to certain rules. I can 't figure out exactly how to specifically generate star systems (points) into sectors (constellations) that need to be taken. Please, tell me how exactly this generation is called, if there are examples or links to the code, I will be very grateful!

I have just the right tutorial for you.
Let me find it.

edit:
Here you go, it’s not C# but C++, but everything is explained in plain words (and the code is quite similar, don’t be too afraid), and is exactly what you want

If you are unsure how to translate the concepts to Unity, ask me in this thread or make another one with a link to this one, so that the others might join as well.

1 Like

If you want strictly what you explained – i.e. you don’t care about persistent procedural generation – but you’re concerned with how to partition space, just confirm this, we can talk about this as well. There are couple of potential techniques you could employ to partition space, in order to generate an almost equidistant graph of stellar systems.

edit:
Try googling Poisson Disc sampling. That’s one of the easiest techniques you could employ.
There are proper tutorials by Sebastian Lague and The Coding Train on the topic.

1 Like

What you want is a graph, once you have random points scattered you need to do “delaunay” then randomly drop link (or promote link) based on what you want to do. IMHO I would use a promotion type of generation after finding the delaunay graph:

  1. put all points in the unprocessed list
  2. choose a random point in that list, put it in the active list,
  3. choose 1 to max random links that have this point
  4. put all the points that are linked in the active list
  5. choose min to max iteration, and repeat the cycle from 3 for all points in active list
  6. put all the point in active list in the closed list, repeat from 2
1 Like

That’s actually an awesome algorithm, that I was shy to suggest because I don’t know if that’s too much for the OP.

I would, in fact, do Voronoi from Delaunay, and work on those edges instead. Basically demote all triangles to centroids, but keep their neighbors as links. edit: Nope, it’s not the centroids, I flipped it on the head (voronoi centroids are delaunay nodes), has to be properly intersected to find voronoi cells, but you know what I mean; the graph is much more interesting that way.

edit:
Though now when I look at it, maybe you’re right. Maybe delaunay is just perfect.

1 Like

@orionsyndrome @neoshaman Thanks for the replies. If I have any questions I will ask you