Check vars when instances of same object collide?

Get help using Construct 2

Post » Wed May 08, 2013 5:31 pm

Hi,

I thought I posted this earlier, but I must have not, because I can't find it when I search. In any case, how can I have two objects of the same type, and do a variable check on collision and then do something to one of them based on the results of the var check?

Thanks in advance
-Chris
B
17
S
4
G
4
Posts: 143
Reputation: 4,004

Post » Wed May 08, 2013 5:43 pm

Object 1 is overlapping Object 2 -> Actions here

or, if the objects are using any behavior, you could:

Object 1 hit Object 2 -> Actions here.
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,192
Reputation: 18,301

Post » Wed May 08, 2013 5:48 pm

This is for situations where both objects are Object 1. For example, if you've played Osmos, it has two Planet objects with a size variable. On collision, the smaller Planet is destroyed and the larger planet gains size equal to the smaller planet's size. How can something like that be done in C2?
B
17
S
4
G
4
Posts: 143
Reputation: 4,004

Post » Wed May 08, 2013 5:57 pm

first event checks for collision

second event could be sub event that checks the size variable and such.
B
40
S
10
G
5
Posts: 102
Reputation: 6,602

Post » Wed May 08, 2013 6:10 pm

How do you tell C2 which two objects to look at, and then which objects to do the processing on? Could you put together a capx, if you wouldn't mind? I've been puzzling with this issue for a while.
B
17
S
4
G
4
Posts: 143
Reputation: 4,004

Post » Wed May 08, 2013 6:20 pm

So basically you have a single object you are duplicating and adjusting the size on each one. Then when two of these objects collide, you want the smaller one to be destroyed and the larger one to grow? Is that right?
B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

Post » Wed May 08, 2013 6:23 pm

Yes, thanks.
B
17
S
4
G
4
Posts: 143
Reputation: 4,004

Post » Wed May 08, 2013 7:16 pm

Use families then.

Put object 1 inside a family.

check object 1 overlapping or hitting family -> actions.

Actions could be -> destroying the object 1 who collided, or, the family (it means the object inside that family, who collided...)TELLES08082013-05-08 19:18:43
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,192
Reputation: 18,301

Post » Wed May 08, 2013 9:23 pm

Here's an example how to handle collisions between same objects:

Evil sprites

Has some variable comparisons too.vee412013-05-10 12:51:12
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Thu May 09, 2013 3:55 am

Unfortunately, there really isn't an elegant solution to being able to easily do subconditions / actions across each distinct instance between collidee and collider in an On Collision based on a single Family at this time.

You can get around this by duplicating the Family. So you have OriginalFamily and DuplicateFamily with the same set of collidable objects.

Then you can do:
OriginalFamily On Collision DuplicateFamily : Actions

While this solves the problem of being able to access both objects distinctly in the same descending subevent tree, you lose access to behaviors and instance variables that belong to OriginalFamily when referring to the DuplicateFamily collision instance.

I've gotten around this somewhat through the use of "System Pick nth instance". In this approach, you pick each one in a separate subevent and save off the information you need to local variables. For example, let's say you had a list of monsters (Ogre, Troll, Imp, Al Sharpton, etc), all of which belong to family called Monsters. You needed X/Y and a custom Family variable called Life. Your code would look similar to this:



Make sense?
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Next

Return to How do I....?

Who is online

Users browsing this forum: MarkThomas and 16 guests