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

0 favourites
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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 ?

  • 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.

  • "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 ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That destroys only one of the two colliding objects. But you can achieve the same thing with many different conditions as well.

  • 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?

  • 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.

    free image hosting

  • 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.

  • 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.

  • >

    > 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?

  • 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.

  • 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.

    Cool Thank you, and sorry I forgot to say that I use the instances in family are static so the player can check collision against them and I was having big Fps drops, but when I deactivate check collisions works normal, and I wasn't sure if by adding choose instance (0) was the problem, Thank anyway for your time

  • Is the collision check in a root event (not a sub), and is it the 1st condition in that event ?

    Do you use a tilemap for static things ?

  • Is the collision check in a root event (not a sub), and is it the 1st condition in that event ?

    Do you use a tilemap for static things ?

    Is in the root event but I do spawn the static objects, im not sure if I can use tilemap for spawn objects,

    I will leave one picture so you have an idea: also is there any other alternative instead of checking collisions like maybe is in a very close distance? that have better performance?

  • That destroys only one of the two colliding objects. But you can achieve the same thing with many different conditions as well.

    it works very well.. thanks alot !

  • tarek2

    No, you can not use a tilemap as a replacement for randomly spawning those sprites.

    I asked because a tilemap is also a pretty optimised object.

    I asked this other questions because C2 has the collisions well optimised.

    https://www.scirra.com/blog/ashley/6/co ... on-in-r155

    You lose that optimisation if the collision/overlap check is not the first condition in a root event.

    Still assuming that we speak about static objects. If you drop the collision cell optimisation, you better bring something in place that is almost as fast. And the only thing (that i am aware off) that is fast enough to beat that optimisation is the Line Of Sight.

    But lets compare. Only testing reveals something in C2.

    This is a bunch of STATIC objects and one moving sprite. Look in the debugger, and see the collision checks running out of control. Yet, the performance drop is minimal. Well, on my laptop. It is kinda fast, dont know on your device.

    https://www.dropbox.com/s/9y6q7s6c4wy73 ... .capx?dl=0

    Now, lets bring those collision checks under control. Using LOS.

    https://www.dropbox.com/s/zzz5ifttiom7b ... .capx?dl=0

    Neglectable collision checks now. You see ? Yet the performance is almost the same. What we won by getting those collision checks under control, we lose by bringing them under control. CPU wise.

    Conclusion: Static objects do not kill performance. That is because they have no 'personal ambitions'. If you have a performance drop, it is not because the amount of objects/instances. It depends on how many objects you apply how many 'personal actions' on in 1 tick.

    Well, that is my experience so far. I am still no expert though.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)