Hi, I am working on an rpg space based game and I want to procedurally generate the unverse for reasons of efficiency. Here is my script so far it’s pretty basic but is working kind of…
the issue I am having is when it randomly spawns a star it is ment to spawn a random amount of planets like a solar system. but when I run game everything spawns ok except the planets spawn from the point of the empty gameobject the script is attached to (as a child of it’s “host Star”) I have tried running 2 different scripts one to spawn the stars and then each star with a script to spawn the planets but both ways run into the same problem…
` public GameObject Seed; public int SpacingMax = 50; public int SpacingMin = 25; public int ScaleMax = 10; public int ScaleMin = 5; void Start () { int size = Random.Range(5, 10); float[,,] SpaceTime; SpaceTime = new float[size, size, size]; for (int a = 0; a < SpaceTime.GetLength(0); a++) { for (int b = 0; b < SpaceTime.GetLength(0);b++) { for (int c = 0; c < SpaceTime.GetLength(0); c++) { SpaceTime[a, b, c] = Random.Range(0, SpacingMax); } } } for (int a = 0; a < SpaceTime.GetLength(0); a++) { for (int b = 0; b < SpaceTime.GetLength(0); b++) { for (int c = 0; c < SpaceTime.GetLength(0); c++) { if (SpaceTime[a, b, c] >= SpacingMin) { int s1 = Random.Range(ScaleMin, ScaleMax); int s2 = Random.Range(ScaleMin, ScaleMax); int Scale = (s1 + s2) / 2; int space = Random.Range(SpacingMin, SpacingMax); GameObject UniVerse = (GameObject)Instantiate(Seed, new Vector3(a * space, b * space, c * space), Quaternion.identity); UniVerse.transform.localScale = new Vector3(Scale, Scale, Scale); UniVerse.transform.parent = this.transform; } } } } } } `` `
what I would like to know is… am I on the right track? if so anymore direction would be handy and if not what would be a better way to do this?