Checking collision between 2 objs of same family

Get help using Construct 2

Post » Mon Apr 23, 2012 6:08 am

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:
http://dl.dropbox.com/u/71080256/TEST.capx
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Apr 24, 2012 1:57 am

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?




kittiewan2012-04-24 02:00:56
B
29
S
11
G
12
Posts: 281
Reputation: 11,888

Post » Tue Apr 24, 2012 2:30 am

You could make a second family and test if family1 collides with family2.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Apr 24, 2012 5:04 am

[QUOTE=Kyatric] You could make a second family and test if family1 collides with family2.[/QUOTE] Ya I know but for my game to work it need to be only 1 family =/
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Apr 24, 2012 5:06 am

[QUOTE=kittiewan] 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?




[/QUOTE]
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 ;)
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Apr 24, 2012 5:11 am

I had the same problem in CC, and I use Kyatric's solution before.rexrainbow2012-04-24 05:11:25
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Tue Apr 24, 2012 5:33 am

[QUOTE=rexrainbow] I had the same problem in CC, and I use Kyatric's solution before.[/QUOTE] 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 ;)
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Apr 24, 2012 6:51 am

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.
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Thu Apr 25, 2013 7:11 am

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?
Jack of all trades, and master of some.
B
29
S
9
G
7
Posts: 174
Reputation: 7,601

Post » Thu Apr 25, 2013 7:28 am

[QUOTE=JoyfulDreamer] 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?[/QUOTE]

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.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Next

Return to How do I....?

Who is online

Users browsing this forum: abdalghani, Kagubro and 23 guests