[Solved]How do I spawn object on array without overlapping?

Get help using Construct 2

Post » Sun Dec 13, 2015 11:41 pm

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.
Last edited by mrneko on Mon Dec 14, 2015 4:56 am, edited 1 time in total.
B
23
S
10
G
2
Posts: 104
Reputation: 3,071

Post » Sun Dec 13, 2015 11:51 pm

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 14, 2015 2:24 am

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.
B
17
S
6
G
1
Posts: 41
Reputation: 1,725

Post » Mon Dec 14, 2015 4:55 am

@LittleStain

Thanks. Made a bit of modification based on your suggestion and it worked.

@Maukka
Thanks for your input too.
B
23
S
10
G
2
Posts: 104
Reputation: 3,071

Post » Mon Dec 14, 2015 4:55 am

@LittleStain

Thanks. Made a bit of modification based on your suggestion and it worked.

@Maukka
Thanks for your input too.
B
23
S
10
G
2
Posts: 104
Reputation: 3,071


Return to How do I....?

Who is online

Users browsing this forum: David181, evillair, tarek2 and 55 guests