How do I pick 2 instances colliding from the same family?

0 favourites
  • 10 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hi, i want to check collision of 2 objects (which could be the same) from the same family.

    In the case they collide they should be both damaged. curretly only one gets the whole damage.

    can someone points me in the right direction? i have marked my current attempt yellow.

    Both glassblocks are also in the family glassblocks

    Kind regards

    Patrick

  • Make a second family with the same items, then compare one against the other.

  • blackhornet

    Thansk for the suggestion, but if i understand correctly i would have to add physics to the second family also. because if not the

    family.physics.velocity[/code:2bh4mb6g] would not be available right? and when i apply 2 physics behaviors to one object it would end in chaos  
     
    regards  
    Patrick
  • This tutorial should help and doesn't require a duplicate family: https://www.scirra.com/tutorials/556/un ... o-families

    Solution 3 should be what you're looking for.

  • ThomasP

    thanks for pointing it out, ive already read it several times. so maybe i am to dump to understand it or maybe i just need another solution.

    so problem is i am not only have to compare 2 instances but 20 or more.

    i can set a instance variable to the uid at the start of layout, no problem.

    but my question is, how do i pick (damage ) BOTH instances participating in the collision out of 20 existing, not only one.

    regards

    Patrick

  • Wouldn't using pick nth instance work for this?

    From the manual:

    Pick Nth instance

    Pick the instance at a given place in the internal list of picked objects. This is most useful used in sub-events to act on separate instances. For example, in a "Sprite collided with Sprite" event, Pick 0th instance and Pick 1st instance can be used to act on each instance involved in the collision separately.

    By the way, if you just use family on collision with family wouldn't both be affected (because both instances are referenced in the event) ?

  • [quote:jexrjq3k]Pick Nth instance

    Pick the instance at a given place in the internal list of picked objects. This is most useful used in sub-events to act on separate instances. For example, in a "Sprite collided with Sprite" event, Pick 0th instance and Pick 1st instance can be used to act on each instance involved in the collision separately.

    THAT should work! thank you so much for pointing that out! i dont know how i could possible have missed that!

    [quote:jexrjq3k]By the way, if you just use family on collision with family wouldn't both be affected (because both instances are referenced in the event)

    Thats what i thought and tryed, but only one object is affected. i think construct at this point pics the first or a random instance and applys the effect.

    what i will do now is to pick each instance (mostly 0,1) and apply the effect. that should work!

    thanks again for pointing this out!

    Regards

    j0schi

  • LittleStain it worked!

    For the record, here is my solution:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Isn't pick Nth instance what the tutorial I linked with solution 3 showing? This is the internet, so I feel it necessary to point out that this is a serious question and I'm not trying to be a sarcastic jerk. I may be misreading the tutorial, which would certainly not be the first time for that.

  • ThomasP yea you are right, but somehow i couldnt make the connection in my brain... however since i am aproched it from a diferent line of view it all makes sence now lol

    my bad

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