Hi,
I have an array of 4 x 4 representing grids.
I want to spawn 3 objects randomly on the grids without overlapping. Is there an easy way to do it? So if object 1 spawns on array (1,0) then the next 2 object will spawn somewhere other than on that grid.
One way to do it is create a function spawn
system repeat 3 times call function spawn
on function spawn
create object at random grid position
object on created
object is overlapping object
object destroy call function spawn
object destroy
call function spawn
Develop games in your browser. Powerful, performant & highly capable.
Another way might be to change the array value after picking it(you could add another z level if you for some reason can't change current values) so that you can check it when picking and repick if it it picked a already set value.
LittleStain
Thanks. Made a bit of modification based on your suggestion and it worked.
Maukka
Thanks for your input too.