Build Random Planet

In this case, I would like to build a random planet. Right now the system still needs to build each of the planets. As part of generation, I need to build planet that different with each other.

As the result, I need to access all variable to build the planet and use Random.Range syntax to create random value for size and terrain. For the color, I use Random.ColorHSV syntax.

Right now, I limit the number of planet user can build maximum 10 Planets, because computational reason.

The code I use are to set Shape and Color

Set Shape
 GameObject.Find(NameOfPlanet).GetComponent<Planet>().resolution = 50;

        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.planetRadius = Random.Range(2, 14);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].enabled = true;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.filterType = NoiseSettings.FilterType.Simple;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.simpleNoiseSettings.strength = Random.Range(0.10f, 0.22f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.simpleNoiseSettings.numLayers = Random.Range(2, 5);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.simpleNoiseSettings.baseRoughness = Random.Range(0.90f, 1.30f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.simpleNoiseSettings.roughness = Random.Range(3.00f, 6.00f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.simpleNoiseSettings.persistance = Random.Range(0.30f, 0.50f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[0].noiseSettings.simpleNoiseSettings.minValue = Random.Range(0.80f, 1.00f);

        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].enabled = true;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].useFirstLayerAsMask = true;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.filterType = NoiseSettings.FilterType.Ridgid;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.strength = Random.Range(0.50f, 2.00f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.numLayers = Random.Range(2, 5);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.baseRoughness = Random.Range(0.90f, 5.00f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.roughness = Random.Range(3.00f, 10.00f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.persistance = Random.Range(0.30f, 2.70f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.minValue = Random.Range(0.80f, 2.00f);
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().shapeSettings.noiseLayers[1].noiseSettings.ridgidNoiseSettings.weightMultiplier = Random.Range(0.20f, 0.75f);
Set Color
GradientColorKey[] colorKey;
        GradientAlphaKey[] alphaKey;

        colorKey = new GradientColorKey[3];
        colorKey[0].color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        colorKey[0].time = 0;
        colorKey[1].color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        colorKey[1].time = Random.Range(0.25f, 0.75f);
        colorKey[2].color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        colorKey[2].time = 1;

        alphaKey = new GradientAlphaKey[2];
        alphaKey[0].alpha = 1.0f;
        alphaKey[0].time = 0.0f;
        alphaKey[1].alpha = 1.0f;
        alphaKey[1].time = 1.0f;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().colorSettings.biomeColorSettings.biomes[0].gradient.SetKeys(colorKey, alphaKey);

        GradientColorKey[] colorKeyOcean;
        GradientAlphaKey[] alphaKeyOcean;

        colorKeyOcean = new GradientColorKey[3];
        colorKeyOcean[0].color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        colorKeyOcean[0].time = 0;
        colorKeyOcean[1].color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        colorKeyOcean[1].time = Random.Range(0.25f, 0.75f);
        colorKeyOcean[2].color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        colorKeyOcean[2].time = 1;

        alphaKeyOcean = new GradientAlphaKey[2];
        alphaKeyOcean[0].alpha = 1.0f;
        alphaKeyOcean[0].time = 0.0f;
        alphaKeyOcean[1].alpha = 1.0f;
        alphaKeyOcean[1].time = 1.0f;
        GameObject.Find(NameOfPlanet).GetComponent<Planet>().colorSettings.oceanColor.SetKeys(colorKeyOcean, alphaKeyOcean);
       
Total Different Planet
(Visited 7 times, 1 visits today)

Related Post

Leave a Reply