Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Hello again...

Ok, a few things...

- Your timer tries to work in a way that it will create 'limit' gameobjects every 'rate' seconds, non-stop. And the only condition to stop it is 'parent.transform.childCount < limit'. You can improve this, both the timer mechanic and the condition used. The problem with this condition is working with something that may be used by another script (counting the childs of the objectToSpawn parent node). In other words, an element that it's outside your script's scope.  

That's two things actually.

- GetModifier(). You have set a single range to obtain values from (and in a hardcoded way). This will limit you to a square, in best of cases. And later, you apply a second random generation that will give you a negative value most of the time. So positions will concentrate mostly on one corner of that square.

That's two things again...

Now a little theory. For a rectangle, in your case, the fastest way to define it is by placing two position vectors: (x1, y1) and (x2, y2). If you want to take a new 'X' contained inside the rectangle, take a random value between x1 and x2. The same way with the new 'Y' value. 

Vector2 newPosition = new Vector2(Random.Range(x1,x2), Random.Range(y1,y2));

I imagine you want to try your own solution (I've noticed you're not reusing the code I left for you), and that's a good thing. Trying to find an alternative and possibly better solution. But remember that you will find later yourself with the problem of overlaping positions. What I think it is the original problem you write the post about.

Hope this helps you to find a solution. 

If you need to ask again, do not hesitate.

Cheers!

(1 edit)

Okay, I'll give test, and thank you.