I'm looking for some information or advice again. As I continue learning Fusion, I give myself challenges that would be useful for a game I will work on in the future, and I try to solve them by myself. And every now and then I come upon a problem that I just can't seem to solve. So here is one I'm stuck at now.
I'm trying to spawn 10 objects with random location, but without overlapping. Here's what I came up with
- On key press (space) I start fast loop "spawn" 10 times
- On fast loop "spawn" i create object A and move it to x rrandom(0,640) and y rrandom (0,480).
It creates 10 objects on random locations but often they overlap, so I added
-Object A overlaps object A : destroy object A
So now I usually end with 8 and sometimes 6 objects, depending of how many of them overlap. Now for game I'll be working on, this will not be a problem as it would give it even more randomnes. But I would still like to figure out how to end up with all 10 objects.
Is there a way to keep running fast loop until there are 10 objects left without overlapping? Or a way to look for overlapping inside fast loop? It kind of looks weird at the moment actually seeing objects get deleted after spawn.
I tried adding:
- object A overlaps object A: destroy object A
: run fastloop "spawn" 10 times minus number of object A
but didn't get any good results
I have a feeling there's something really simple I'm missing but I just can't seem to figure it out at the moment