Destroy The same type object that collide with another...

Get help using Construct 2

Post » Tue Mar 14, 2017 12:26 pm

Destroy The same type object that collide with another Object that has the same type too ?
so everytime i run my game.. it will spawn 5 same object at random position (lets call it "Brick") so.. if the brick is spawned on start of the game.. and it collides with another brick.. let say... 2 bricks are colliding with one another.. so i want to take out one of them.. not both of them.. i used "destroy" feature.. it destroys both of them... help ?
B
8
S
3
Posts: 46
Reputation: 708

Post » Tue Mar 14, 2017 12:57 pm

Use "is brick overlapping brick" and then pick one of them with another condition. After that you use the destroy action and it will only destroy the picked one. Use trigger once if it is not a subevent of a trigger.

You can also do it with on collision with brick and then a condition that picks one of them to destroy as well.
B
57
S
24
G
14
Posts: 773
Reputation: 13,137

Post » Thu Mar 16, 2017 8:17 am

"You can also do it with on collision with brick and then a condition that picks one of them to destroy as well" what is the condition ? can you give me the example ?
B
8
S
3
Posts: 46
Reputation: 708

Post » Thu Mar 16, 2017 8:52 am

Image

That destroys only one of the two colliding objects. But you can achieve the same thing with many different conditions as well.
B
57
S
24
G
14
Posts: 773
Reputation: 13,137

Post » Thu Mar 16, 2017 1:21 pm

Anonnymitet wrote:Image

Sorry but doesn't this destroy Brick Instance (0) ?
I can imagine Brick(2) and Brick(3) colliding and Brick(0) disappearing for no reason.
I could be wrong but would someone clarify this?
Image Image Image
B
32
S
12
G
27
Posts: 761
Reputation: 17,244

Post » Thu Mar 16, 2017 2:41 pm

@MPPlantOfficial It destroys the oldest instance by doing it that way no matter what instance number the objects has. I tried and it works perfectly no matter what objects are colliding only one of the two was destroyed everytime.

So if instance(3) and instance(4) collided then only one of them was destroyed anyway.

As you can see it works for all instances. The boxes are instances of the same object but with different animation frames. You can also use "pick random instance" as a condition on the collision event instead and it will pick one of the two colliding instances at random to destroy.

Image
free image hosting
B
57
S
24
G
14
Posts: 773
Reputation: 13,137

Post » Thu Mar 16, 2017 6:14 pm

MPPlantOfficial wrote:Sorry but doesn't this destroy Brick Instance (0) ?
I can imagine Brick(2) and Brick(3) colliding and Brick(0) disappearing for no reason.
I could be wrong but would someone clarify this?


Brick(0) is always the instance with the first index in the Selected Object List (picklist), also the 'oldest' in the picklist.

Using 'On collision' picks two bricks (if only 2 collide), those are Brick(0) and Brick(1), even if you have 100 other bricks in the game.

Using no pick condition is the same as using 'pick all', so now all Bricks are in the picklist and Brick(0) is (with all picked) the 'oldest' instance overall.

Brick(-1) is then newest instance.

So, the index ALWAYS refers to the index in the picklist.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Mar 16, 2017 9:36 pm

99Instances2Go wrote:Brick(0) is always the instance with the first index in the Selected Object List (picklist), also the 'oldest' in the picklist.

I see. So THAT's why when I attempted to make Breakout, the (0)'th instance got destroyed when the ball collided with a bar. Thanks for clearing that up.
Image Image Image
B
32
S
12
G
27
Posts: 761
Reputation: 17,244

Post » Thu Mar 16, 2017 11:02 pm

99Instances2Go wrote:
MPPlantOfficial wrote:Sorry but doesn't this destroy Brick Instance (0) ?
I can imagine Brick(2) and Brick(3) colliding and Brick(0) disappearing for no reason.
I could be wrong but would someone clarify this?


Brick(0) is always the instance with the first index in the Selected Object List (picklist), also the 'oldest' in the picklist.

Using 'On collision' picks two bricks (if only 2 collide), those are Brick(0) and Brick(1), even if you have 100 other bricks in the game.

Using no pick condition is the same as using 'pick all', so now all Bricks are in the picklist and Brick(0) is (with all picked) the 'oldest' instance overall.

Brick(-1) is then newest instance.

So, the index ALWAYS refers to the index in the picklist.



@99Instances2Go Thanks for the explanation very useful to know, I have one question, doing it like that does it make any difference on performance if you have 100 of the same instance or is the same thing?
B
40
S
22
G
81
Posts: 297
Reputation: 44,735

Post » Thu Mar 16, 2017 11:58 pm

There is no other choice then 'doing it like that'.

It is not the amount of instances (of objects for that matter) that weight on performance in the first place, it is the amount of instances that you give a personal (each instance different) 'touch'. Like moving them in different directions based on conditions, test for collisions (also a personal thing) and overlaps, giving them all a personal pathfinder ..... etc.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests