How do I Random location without overlap

Get help using Construct 2

Post » Sun Jul 06, 2014 6:32 am

Hi
I am using a action Create Object Random (100,1500),Random(100,500))
All works fin except I Create 10 of this items with a delay of 1 sec but sometimes the items overlap and I wane avoided that. Is that possebel?
B
13
S
3
G
1
Posts: 36
Reputation: 908

Post » Tue Jul 08, 2014 12:56 am

Hi,
You should provide more details about what you're trying to achieve if you want solutions which are optimal for your project, but I think the best way to achieve this is to spawn an invisible sprite instead of your object, then, as a sub-event, spawn your object if this sprite isn't overlapping with your object. (a collision detector)
B
4
Posts: 1
Reputation: 204

Post » Tue Jul 08, 2014 3:18 pm

After spawning the objects, check if their overlapping and if so randomize position again, it works if you have a small number of objects and alot of space to position them. Otherwise it will get stuck in that loop trying to reposition the objects forever, because it can't find a position that doesn't overlap.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Tue Jul 08, 2014 4:37 pm

You can also push out via the custom movement behavior or manually via events, or use physics.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Post » Wed Jul 09, 2014 8:30 am

Thanks for help It workt fine.
B
13
S
3
G
1
Posts: 36
Reputation: 908


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], David181, evillair and 60 guests