Collision between instances of the same object

Get help using Construct 2

Post » Wed Jul 03, 2013 10:26 am

Hi there,

I some advice for how I best accomplish the following task:
I need to check for collisions between instances of the same object. This is so that autonomous AI will be able to exchange information when they get "in touch" with each other.

So what I need to do is when instance A collides with instance B one of instance B instance variables should be set to the same value as the instance Variable instance has.

What is the most simple way to do this?

Thank you in advance,
Jimmy
B
8
S
3
G
2
Posts: 45
Reputation: 2,193

Post » Wed Jul 03, 2013 12:31 pm

Unfortunately, the collision check will work in both ways. When A hits B, B hits A in the same time. Even with logic, I don't see how we could determine which hit which. What you can do though is transfer a variable from one of the instance to the other, distinguishing A and B with a rule based on their instances (for example, let's says that A is the variable that was created first, so with the smaller UID).
I set up a little capx for example. You can drag the sprites to have the collision append. You'll see that the second instance is taking the value of the first one.
capx

One last thing, if you want the collision to happen only in one way, you can "lock" the instances one they are picked up in the first way (toggleing a Boolean), and add a check on this Boolean in your collision check.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Wed Jul 03, 2013 12:36 pm

Here is an example how you could do it. The sprites can 'infect' non-infected sprites. Basically what happens, is that the collision event has both sprites selected and you'll just need to determine what to do with each one.

Evil Sprites Examplevee412013-07-03 13:44:42
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Post » Wed Jul 03, 2013 1:00 pm

@vee41
love the face of your evil sprite ^^ And I learned something from your capx too, so thanks ! (btw, you have a space at the end of your link making it broken)
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Wed Jul 03, 2013 1:44 pm

[QUOTE=Guizmus] @vee41
love the face of your evil sprite ^^ And I learned something from your capx too, so thanks ! (btw, you have a space at the end of your link making it broken)[/QUOTE]

Thanks! Fixed the link :)
B
24
S
9
G
7
Posts: 756
Reputation: 7,312

Post » Wed Jul 03, 2013 3:31 pm

Thanks for the tips guys! :) I could probably make use of it.
B
8
S
3
G
2
Posts: 45
Reputation: 2,193

Post » Wed Jan 08, 2014 6:51 pm

I know this is really late to the show, but I put together a tutorial for same on same instance collision between sprites based on the evil sprites demo: I can't post URL's yet so please search for the tutorial "How to handle instances of same sprite collision / colliding."
B
31
S
7
G
1
Posts: 80
Reputation: 2,550


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests