Check vars when instances of same object collide?

0 favourites
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi,

    I thought I posted this earlier, but I must have not, because I can't find it when I search. In any case, how can I have two objects of the same type, and do a variable check on collision and then do something to one of them based on the results of the var check?

    Thanks in advance

    -Chris

  • Object 1 is overlapping Object 2 -> Actions here

    or, if the objects are using any behavior, you could:

    Object 1 hit Object 2 -> Actions here.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is for situations where both objects are Object 1. For example, if you've played Osmos, it has two Planet objects with a size variable. On collision, the smaller Planet is destroyed and the larger planet gains size equal to the smaller planet's size. How can something like that be done in C2?

  • first event checks for collision

    second event could be sub event that checks the size variable and such.

  • How do you tell C2 which two objects to look at, and then which objects to do the processing on? Could you put together a capx, if you wouldn't mind? I've been puzzling with this issue for a while.

  • So basically you have a single object you are duplicating and adjusting the size on each one. Then when two of these objects collide, you want the smaller one to be destroyed and the larger one to grow? Is that right?

  • Yes, thanks.

  • Use families then.

    Put object 1 inside a family.

    check object 1 overlapping or hitting family -> actions.

    Actions could be -> destroying the object 1 who collided, or, the family (it means the object inside that family, who collided...)

  • Here's an example how to handle collisions between same objects:

    Evil sprites

    Has some variable comparisons too.

  • Unfortunately, there really isn't an elegant solution to being able to easily do subconditions / actions across each distinct instance between collidee and collider in an On Collision based on a single Family at this time.

    You can get around this by duplicating the Family. So you have OriginalFamily and DuplicateFamily with the same set of collidable objects.

    Then you can do:

    OriginalFamily On Collision DuplicateFamily : Actions

    While this solves the problem of being able to access both objects distinctly in the same descending subevent tree, you lose access to behaviors and instance variables that belong to OriginalFamily when referring to the DuplicateFamily collision instance.

    I've gotten around this somewhat through the use of "System Pick nth instance". In this approach, you pick each one in a separate subevent and save off the information you need to local variables. For example, let's say you had a list of monsters (Ogre, Troll, Imp, Al Sharpton, etc), all of which belong to family called Monsters. You needed X/Y and a custom Family variable called Life. Your code would look similar to this:

    <img src="https://dl.dropboxusercontent.com/u/12667027/Construct%202/IdenticalObjectCollision/MonstersExample.png" border="0" />

    Make sense?

  • can't you do

    On Collision Monster with Monster

    -- Compare Two Values( Monster(0).X > Monster(1).X )

  • edit: Read it wrong. thought it was player and planet. not planet and planet.

  • I have used this in a project recently, it is what you had in mind?

    <img src="http://i.imgur.com/LUC6FzX.png" border="0" />

  • I'm getting a 400 error on that link, could you reupload please?

  • jayderyu

    That won't work. As Ashley has stated in the past, Indexing by IID is not limited to the SOL (list of selected objects).

    See my earlier response to this thread for workarounds.

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