How do I destroy the correct overlapping objects(same types)

0 favourites
  • 8 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • [attachment=0:2vwo61bm][/attachment:2vwo61bm]

    I have icicles fall from the sky and land randomly on the floor. I want to have an event check if any of the shadows, spawned under the icicles before they fall (showing the player where to not stand), are overlapping, then destroy the shadows and corresponding icicles to those shadows.

    Currently it will kill the correct shadows but the icicles will get destroyed, more than they are suppose to.

    I tried only having the shadows overlapping as the only condition but still if any shadows are overlapping all the icicles get destroyed, not just the icicles that have shadows overlapping.

    Here is my algorithm. What am I doing wrong?

    [attachment=2:2vwo61bm][/attachment:2vwo61bm]

    [attachment=1:2vwo61bm][/attachment:2vwo61bm]

    I think it doesn't get the icicle number right since they are all of the same object and have different id numbers.

    I was hoping for it to check after each shadow spawned and then destroy the objects then before the next shadow spawned but i think it spawns all the shadows and objects then checks for overlap and cant figure out which icicle to kill....

    Any Help will be greatly appreciated thank you. I am still very new to designing games and get lost easy.

  • without seeing your capx...

    have you tried an event like:

    system> pick overlapping point > object: icicle, x: icicleshadow.x, y: icicleshadow.y

  • Added an Simplified Example Capx. in the main post. Still cant figure it out searched the forums no idea how to fix it?

    I have a feeling it does have something to do with picking the right ones but I always seem to get all the icicles or all the shadows never the right ones.

    Tried something like:

    Function "check icicle"

    (and)pick icicleshadow where icicleshadow.uid>icicleshadow.uid

    (and) icicleshadow is overlapping icicleshadow

    ------> Destroy icicleshadow

    The idea being to call the function every time a new icicle is spawned, then check if any icicles were overlapping each other and compare all the uid's. If any were (since it was called every time one spawned) it would have to be the one with the highest uid. so pick that one and destroy it.

    long shot and didn't work heh

  • HadesDC Now that I see the capx I think I understand. I think I have some ideas to try.

    Just so I am clear:

    is Sprite 2 just the method you used to set the correct position of icicleshadow from icicle?

    does Golem have a function in your game or is it just used to set the initial position of icicle?

  • What I did in one of my games was to check if they were overlapping, then pick a random instance and it worked. Not sure if it's the best way to do it though.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try this:

  • HadesDC what alextro suggests will work as long as you keep that event outside the function "Icicle Drop" because you are using a keystroke as a trigger. Moving the shadows is ideal to destroying them. It is a bit slow the more objects you have on the screen.

    [attachment=1:9htxyqnv][/attachment:9htxyqnv]

    Here is another similar option where I have added some ideas on how to better control your icicles including putting the icicle/shadow in a container and the hit icicle/cracks in a container, breaking up the icicle drop function into multiple parts and using a global variable to determine the amount of icicles, not using the golem/sprite 2 to create the icicles/shadows, and I changed some of the triggers so that the icicle fall/ destroy was more organic and you don't see the slow spawn of the icicle shadows when avoiding overlap. You may have some challenges with icicles colliding with the wrong shadows and you may get better performance if you try the move to plugin rather than the bullet movement and use the move to rather than collision. But that is speculative, and you should use your best judgement based on your game design.

    [attachment=0:9htxyqnv][/attachment:9htxyqnv]

    You could also use a recursive function to create each shadow at a distance from the last created shadow (only slightly faster and the pattern would look Fibonacci and less awesome), use a randomized array that has dynamically generated on start of layout non-overlapping spawn points (faster but more complicated), or use set spawn points (fastest but least awesome visually).

    Good Luck! I bet your finished product will be very cool.

  • Wow Thank you both so much this completely fixed my problem and I learned about containers which i have already used in another problem i was having with destroying the correct corresponding stink cloud when one of my skeletons was destroyed.

    Have a good day!

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