0

I am trying to make a system that uses a perlin noise field to generate random positions that are then saved, or saved as the are generated, to a list. Then using that list the game will use those positions to spawn in objects within the level. I think that I might be on the right track, but I might have a few things in the wrong places.

Here is a link to an image of all the things that I think are relevant: enter image description here

the blue dots should be the saved locations that are added to the list. But i am only getting one position 5 times, which is the correct number of positions but they are all the same position that is the problem.

// --- Random Generation of Objects --- //
Color[] colourMap = new Color[mapWidth * mapHeight];

for(int y = 0; y < mapHeight; y++) {
    for(int x = 0; x < mapWidth; x++) {

        float currentHeight = noiseMap[x, y];
        for(int i = 0; i < regions.Length; i++) {

            // --- Random Gen of Asteroids --- //
            if(currentHeight <= regions[i].height) {
                colourMap[y * mapWidth + x] = regions[i].colour;
                Vector3 ping = new Vector3(x, 0, y);
                asteroids.Add(ping);
                Debug.Log(asteroids[i]);
                break;
            }

        }

    }

}

Anyway thank you for the help and reading this far, please let me know if you need anything more.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • Thank you Blorgebeard for the edit, the code function was not working for me. – connor marshall Jun 23 '16 at 06:15
  • Could you try `Debug.Log(ping);` after the asteroids.Add().. and are clearing the list before this? – mgear Jun 23 '16 at 06:19
  • Ok so when I add `Debug.Log (ping);` after `asteroids.Add(ping);` is give me the all 5 positions, that are not the same. So ping is just looping inside `asteroids.Add(ping);` for some reason. [edit] I am not clearing the list before hand because it is just going to get changed when I re-run the script – connor marshall Jun 23 '16 at 06:42
  • `Debug.Log(asteroids[i]); ` only prints the first items from 0 to regions.Length, since the `i` loops between them. But in your list they should be correct then. – mgear Jun 23 '16 at 08:01
  • Thank you for the help. It was just that the `Debug.log()` was in the wrong location XD. – connor marshall Jun 23 '16 at 09:27

0 Answers0