How do I detect collisions between two SPECIFIC instances

  • how do i detect a collision between two specific instances of the same object type?

    i say specific because ive seen posts that just want to differentiate values of their instances but

    i want to detect a collision only between for example sprite with UID 1 and sprite with UID 2,

    or sprite with instance variable 1 and sprite with instance variable 2

    both sprites being of the same object type of course

  • Not sure if there is regular way, although I believe you could "cheat" here.

    Create 2 families, and in both put objects you want to collide. Then pick by first UID first family, by second UID pick second family, and them detect their collision.

    They will be objects of the same type, by defined by different family.

  • i sort of made it with events although not elegant:

    create variable

    when sprite is overlapping sprite

    pick sprite by evaluating IID=0 > add 1 to variable

    pick sprite by evaluating IID=1 > add 1 to variable

    variable = 2 > do event then set variable to 0

    else set variable to 0

    this is really not the solution i hoped, it should be:

    if sprite.IID(0) is overlapping sprite.IID(1)

  • I believe your solution is more hardware demanding because it checks for all collisions and then looks if any collision that happens is the right collision.

    With familliy trick you can pick right instances and then look just at collision between these two.

  • follow me here:

    Sprite -> On collision with Sprite

    System -> Pick Enemy by evaluating Sprite.UID = 1 | Sprite.UID = 2

    System Enemy.PickedCount = 2

    What do you think, blah6546? Those three conditions all go in one event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you know you could try to use instance variables

  • Ash10500 - he already uses UID

    Unnatural20 - in that case it will check all collisions which will eat more resources.

    Best way would be to first pick 2 objects by UID and then check only these two object for collisions.

  • i was about to say that it doesnt work but i was confusing "pickedCount" with "count" aghh

    for some reason i cant see the expressions panel anymore, but yes it does work, perfect,

    also i was going to suggest inverting the order of events but i wanted to test it first and it doesnt work for some reason

    [EDIT1]

    actually it does work but with subevents:

    system pick sprite by evaluating sprite.IID=0|sprite.IID=1

    [subevent] sprite is overlapping sprite

    ---system sprite.pickedCount=2

    brilliant, thanks

    [EDIT2]

    "system > sprite.pickedCount=2" doesnt seem to be necessary in this arrangement

  • bla6546: Ooh, yeah, your solution is even better. Fits RazorMonkey's advice of only checking the collisions of those sprites in particular. You shouldn't even need a subevent; but you might want System -> Trigger Once While True

    I've been testing this on a demo I threw together for another problem someone was having, but check it out:

    When the first two Enemies first are overlapping, they flash for a second.

  • actually you can substitute the variable and the first two events with:

    enemy is overlapping jail > set text to enemy.pickedCount

  • Heh, yeah. Can you tell I'm still learning, too?

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