Object Count

Get help using Construct 2

Post » Mon Feb 17, 2014 5:48 pm

I want that when 3 balls of the same color to touch are destroyed for example, but if two balls touch are not destroyed. And they are destroyed at once.
I tried Count.object but does not work. Any tips?

cesarzevil2014-02-17 20:15:46
B
11
S
5
G
1
Posts: 410
Reputation: 2,802

Post » Tue Feb 18, 2014 3:06 am

I've been looking at this on and off throughout the day, and it's definitely difficult with C2s overlap mechanism. I'm wondering about scope: how many unique objects do you have in mind? If you could attach unique hidden objects per colour, you could detect against them, instead of the objects directly.
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Tue Feb 18, 2014 7:56 am

You need to use recursion to solve this. Here is a capx
https://dl.dropboxusercontent.com/u/30864403/overlap.capx

Probably not the most efficient way, but this is the idea.

In this example, you can drag the objects around until they overlap. The opacity of the objects will change if 3 or more are touching in any sort of formation (e.g. they don't all have to touch each other, just a series of 3 touching).

Instead of destroying the objects, I make their opacity 50%, for demonstration purposes. You can destroy them if you just change that action yourself.

Disclaimer: There may be bugs :PJuryiel2014-02-18 07:56:59
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue Feb 18, 2014 9:01 am

blackhornet:
Say I have 4 balls:
- Blue
- Red
- Green
- Yellow

And only destroy hitting the blue ball with the blue, but in this example you wanted three blue balls collide and are destroyed.

Juryiel: Thanks for the example, I think I can modify it to my liking.cesarzevil2014-02-18 09:06:44
B
11
S
5
G
1
Posts: 410
Reputation: 2,802

Post » Tue Feb 18, 2014 9:07 am

Well, collision isn't made for 3 objects at a time, so it's not easy this way.

I would start by making an "evalSystemState" function, that would eval the system every 0.1s or so. It would examine every ball, one after the other, checking how many other balls were in its vicinity and saving this in a variable on the balls. Once this is done, you would just have to destroy every ball that have 2 or more in this variable.
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Post » Tue Feb 18, 2014 9:39 am

[QUOTE=Guizmus] Well, collision isn't made for 3 objects at a time, so it's not easy this way.

I would start by making an "evalSystemState" function, that would eval the system every 0.1s or so. It would examine every ball, one after the other, checking how many other balls were in its vicinity and saving this in a variable on the balls. Once this is done, you would just have to destroy every ball that have 2 or more in this variable.[/QUOTE]

The problem with that is that if Ball B is in the vicinity of Ball A, and Ball C is in the vicinity of Ball B but NOT in the vicinity of Ball A, then you won't destroy all of the balls when in fact you should (if I understood correctly what the OP wanted).

On the other hand, if the only condition that destroys the balls is when all 3 are touching each other, the problem becomes much simpler, as you say.

As far as doing the detection of one object with multiple objects of the same type, the trick I learned in C1 was to put object A in family A, then pick a given instance of object A, and check it against all instances of family A (except itself). Seems like it works in C2 as well, though I'm not sure if there's a better method. Juryiel2014-02-18 10:06:38
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue Feb 18, 2014 10:18 am

I try to do the example Guizmus? or I'll take yours?
B
11
S
5
G
1
Posts: 410
Reputation: 2,802

Post » Tue Feb 18, 2014 10:31 am

@cesarzevil like @Juryiel said, you must first decide if a ball between 2 other same balls should or not be destroyed, even if those 2 other balls don't touch themselves.
- if yes, then the method I described should work nicely
- if no, then it's more complicated, you would have to store the Ball.UID of all touching balls, not just the count, and then check if those are next to each other or not.
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Post » Tue Feb 18, 2014 10:56 am

when I throw my ball and colliding with two other balls of the same color are destroyed, but then for example there is a total of 6 red balls, and I shot a kill three, then threw another and destroy the other 3. Total destroyed 6 red balls.
I did not know it was so complicated ... I'm about to leave: S
B
11
S
5
G
1
Posts: 410
Reputation: 2,802

Post » Tue Feb 18, 2014 4:54 pm

You're not being very clear about what you want. Think of all the situations all balls on a layout may find themselves in, and describe what you want to happen.

And specifically, if my example isn't doing waht you want, why? What did you need to be different?
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Next

Return to How do I....?

Who is online

Users browsing this forum: irina, Klarner and 29 guests