I am having some trouble with my class project, essentially what I want to do is spawn objects randomly which so far is working perfectly, they are spawned from an 2d array that stores X and Z which have been randomly generated within reasonable distance. The issue I am having is objects being placed inside each other due to lack of duplicate detection. I need to go through the 2d array, see if any X and Y co-ords match and randomize any matches found. Sorry if this doesn't make a lot of sense, i'm not too good at explaining things but perhaps you could take a look at my current detection method and give me some tips?
for (int k = 0; k <= NumofShrooms - 1; k++)
{
for (int i = 0; i <= NumofShrooms - 1;)
{
if (k == i)
{
i++;
}
if (SpawnArray[k][2] == SpawnArray[i][2])
{
SpawnArray[k][2] = rand() % 16 + 1;
i = 0;
}
else i++;
}
}
Aucun commentaire:
Enregistrer un commentaire