Collision between instances of the same object

0 favourites
  • 7 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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

  • 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.

  • 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 Example

  • 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)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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)

    Thanks! Fixed the link :)

  • Thanks for the tips guys! :) I could probably make use of it.

  • 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."

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)