Only pick one of 2 or more instances on collision

Get help using Construct 2

Post » Fri Aug 02, 2013 4:36 pm

I thought I solved this long ago...

But when an object collide with 2 instances simultaneously they are both affected..

I try to avoid this by including : pick random "object" instance.

But it seems not to work.


An exaple file

Help would be much appreciated. WizLore2013-08-02 16:36:47
B
9
S
4
G
1
Posts: 104
Reputation: 2,278

Post » Fri Aug 02, 2013 7:30 pm

Just change form "On collision" to "Is overlapping" and keep the "Pick a random instance".
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Fri Aug 02, 2013 7:45 pm

On not sure exactly what's going on here but it seems like when you say;

A On Collision with B

It resolves one at a time rather than resolving all the collisions then applying actions to the affected instances.

You can see this in action by simply adding "Sprite2 | Set position(0, 0)" to the action list.

You'll notice only one instance of Sprite is affected. As if the first collision resolves, then Sprite2 moves causing the second collision to fail.
B
12
S
4
G
2
Posts: 59
Reputation: 3,799

Post » Fri Aug 02, 2013 8:03 pm

Triggers are different from events. On Collision will only report one at a time. I had a recent example of dealing with this, but I can't find it at the moment. You either have to manage this yourself, or see if Overlap will do what you want.blackhornet2013-08-02 20:04:23
ImageImageImage
B
71
S
21
G
211
Posts: 3,614
Reputation: 119,147

Post » Fri Aug 02, 2013 8:49 pm

Overlap works fine. Thanks.
I don't understand why. but it works.
B
9
S
4
G
1
Posts: 104
Reputation: 2,278

Post » Fri Aug 02, 2013 9:04 pm

On collision occurs when on the first tick an object overlaps another, and picks those objects. Even if it overlaps two objects at the same tick, it triggers on collision with only one object, picks that object and proceeds with the actions. After that it triggers on overlapping the other one.
It basically picked one object, destroyed it, picked the other one and destroyed that one.

With "Is overlapping" it checks whether each instance of an object is overlapping another one and picks all instances that do.
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Sat Aug 03, 2013 7:06 pm

Thanks KFC. Nice to know why things works as they do.
B
9
S
4
G
1
Posts: 104
Reputation: 2,278


Return to How do I....?

Who is online

Users browsing this forum: ashishv, Janaina, shushpo and 5 guests