Checking collision between 2 objs of same family

0 favourites
  • 12 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hey

    How do I check 2 sprites of the same family but with different value of a variable overlapping?

    Example.. I have 2 sprites in a family, sprite 1 and 2, and they have both variable "player", sprite 1 have value 1 and sprite 2 value 2 of player variable.

    When sprites with different value of player variable overlaps, only the sprite with value 2 will be destroyed but there is 10 instances of each sprite in the layout and they go in the direction of each other. So sprite1 overlapping sprite1 don't do nothing and the same for sprite2, only triggers when sprite1 overlaps sprite2 or sprite2 overlaps sprite1.

    If I do something like:

    +family.player (not equal) family.player

    +Family is overlapping family    THEN(action)    destroy family

    it doesn't work.

    So how to make it work??

    Here is the capx example to help understand What I mean:

    dl.dropbox.com/u/71080256/TEST.capx

  • The easiest way to handle this is to use the names of the sprites in the last event:

    Sprite is overlapping Sprite2 -> Sprite2 destroy

    (You don't need the test to see if the player variables are equal.)

    Was there something more you were trying to achieve?

    That is, is there some reason you need to do this with families that you didn't mention?

  • You could make a second family and test if family1 collides with family2.

  • You could make a second family and test if family1 collides with family2.Ya I know but for my game to work it need to be only 1 family =/

  • The easiest way to handle this is to use the names of the sprites in the last event:

    Sprite is overlapping Sprite2 -> Sprite2 destroy

    (You don't need the test to see if the player variables are equal.)

    Was there something more you were trying to achieve?

    That is, is there some reason you need to do this with families that you didn't mention?

    Ya I know this way it works but I need to achieve that with families and both sprites need to be in the same family, why that is because of the system of my game I'm doing, the mechanics, etc. thanks for reply anyway ;)

  • I had the same problem in CC, and I use Kyatric's solution before.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I had the same problem in CC, and I use Kyatric's solution before.Ya that's how I did before too but now I need to find a way to make it work with the sprites in the same family ;)

  • Here is a way:

    http://dl.dropbox.com/u/5426011/examples10/test2.capx

    The red was dominating the blue so I made it pick randomly one of the two colliding objects to destroy.

  • I'm having this same issue. I have instance variables attached to a family and I have to test collision between the SAME family, and access those variables at the same time between both! :/ Is there still no good solution for this?

  • I'm having this same issue. I have instance variables attached to a family and I have to test collision between the SAME family, and access those variables at the same time between both! :/ Is there still no good solution for this?

    Here is one solution, I don't see why it wouldn't work with families as well:

    Evil sprites example

    You could save variable values from picked instance into local variable, and compare those to variables of other instance. Then react accordingly.

  • That's odd. I swear I tried something similar already, but the example seems to work. Better go back and try again. ;) I guess the docs were not too clear on what happens if 3 touch - does it trigger once for all objcets, or ONLY each pair on collisions? (so if 3 objects hit, then the trigger occurs 3 times) I guess it would seem so.

  • Here is one solution, I don't see why it wouldn't work with families as well:

    https://dl.dropboxusercontent.com/u/19921470/evil_sprites_demo.capx

    Evil sprites example

    You could save variable values from picked instance into local variable, and compare those to variables of other instance. Then react accordingly.

    Thanks! That evil sprite demo showed exactly what I was looking for! <img src="smileys/smiley4.gif" border="0" align="middle" /> I've just started experimenting with C2, so I didn't know I could grab the UID and use pick instance in that way.

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