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

Get help using Construct 2

Post » Thu Jul 09, 2015 9:58 pm

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


Image

Kind regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Thu Jul 09, 2015 10:10 pm

Make a second family with the same items, then compare one against the other.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Thu Jul 09, 2015 11:37 pm

@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
Code: Select all
family.physics.velocity
would not be available right? and when i apply 2 physics behaviors to one object it would end in chaos :D

regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Fri Jul 10, 2015 4:27 am

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.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Fri Jul 10, 2015 10:38 am

@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. :D

regards
Patrick
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Fri Jul 10, 2015 10:43 am

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) ?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 10, 2015 3:20 pm

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!


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
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Fri Jul 10, 2015 5:58 pm

@LittleStain it worked!

For the record, here is my solution:
Image
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Fri Jul 10, 2015 6:28 pm

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.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Fri Jul 10, 2015 7:42 pm

@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 :D
B
19
S
7
G
1
Posts: 222
Reputation: 2,551


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests