Trying to destroy overlapping instances of the same object

Not favoritedFavorited Favorited 0 favourites
  • 11 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I know this question has been asked many times before, and I have looked into those threads and used them as the basis for what I have created, but I cannot seem to get this to work.

    I have a BlueprintGenerator object, which is also the only object in the BluePrintDifferentiator Family. I spawn these when I generate a dungeon level, and now I want to check for any BluePrintDifferentiators that are overlapping the current BlueprintGenerator object and destroy them.

    But instead this just deletes ALL of them. There are no BlueprintGenerators in the layout after this runs. I thought that maybe the issue was that the BlueprintGenerators flagged themselves as BluePrintDifferentiators that are overlapping (hence the UID check) but this did nothing.

    What's wrong and how do I get the desired affect?

  • Hello. A long time ago, we used families to handle collisions or overlaps of identical objects.

    But in some update, Construct 3 gained these actions, and now such events can be handled even without families.

    Have you tried it?

  • Thank you for the reply. I've used those actions in other ways but not for this specifically.

    I tried this and it still does not work, now it's not seemingly destroying any of them:

    If I place it outside of the function it does delete them over a couple of seconds... but it deletes ALL of them but one.

  • dropbox.com/scl/fi/z09ckm4w7a2jsb8emsw5u/objectselfcollisionsexample.c3p

    This destroys both of them on collision (overlapping works the same). You can enable the random instance condition to only destroy one randomly. You can otherwise define how you want to pick which one gets destroyed via the available system pick instances group of conditions if you want.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dropbox.com/scl/fi/z09ckm4w7a2jsb8emsw5u/objectselfcollisionsexample.c3p

    I appreciate this a great deal! Unfortunately there must be something else going on because copying that solution exactly (and turning on the random UID pick) still ends up destroying all instances.

    I have a theory that it could be due to my procedural generator. Currently the generator fills out a tilemap, and based on a dice roll it will create a random number of BluePrintGenerators all at the same time in this process.

    In your example the objects are created one at a time over time, could this be an issue?

  • Ah. I'm gonna guess you've got a picking issue when using For Each, since that picks individual sprites from the start, which I think might preclude it from colliding with other sprites. (This should still work fine with the families method though)

    Try using While instead - dropbox.com/scl/fi/e7t25x743f0esab3wcm3m/objectselfcollisionsexample2.c3p

    (Edit: Something is still wrong with this for now... there are sometimes overlapping sprites remaining and I'm not sure why.) Edit 2: Solved - bound to layout was moving things after the start of layout trigger, allowing things to overlap afterwards. This can be resolved by either disabling bound to layout (which I did in the updated example), or by removing the start of layout trigger so it checks every tick for overlap (thus catching the moved objects on the second tick after start of layout).

  • oosyrag Thank you so much, this works perfectly, and I appreciate you following up to track down that layout issue. Very appreciated!

  • Was staring at it some more, and realized that there are some suspiciously large open areas I would have expected to have sprites remaining in.

    I think it has to do with order - a bunch of sprites overlapping in a chain across the entire screen has the potential to all end up deleting each other with only one remaining at the end, even if there was space to leave many of them without overlapping.

    For example, if A overlaps with B and B overlaps with C while C does not overlap with A - If B gets deleted in the first round, A and C will remain. But when comparing A and B and A gets deleted, B is still overlapping C and another one will be deleted leaving only one at the end.

    I don't have a clean way of resolving this off the top of my head... but my suggestion would be to not use such a method of distribution in the first place - brute force spamming instances everywhere and then cleaning up afterwards is less efficient than not placing the instance if the target location would result in overlapping with an existing instance to begin with.

  • You need to prevent overlap checks on sprites that are scheduled to be destroyed.

    Note that the "Destroy" action does not remove the instance immediately; it is processed at the end of the current tick.

    Check this!

    Multi-Sprite Creation with Overlap Destruction

  • Nah, same issue can happen depending on the arrangement of the overlapping and order they are checked. I've already got the equivalent by disabling collision immediately.

    The solution is to keep track of and destroy the instance with the most number of overlapping instances on each iteration. In my previous example, A and C have 1 overlap, and B has 2, which means B should be the one to be destroyed given a choice.

    However, there's no way to get that count without using the old object -> compare with family trick as far as I can tell, by using system instance picking only. When using for each (because we want to count how many are overlapping each individual instance), to get the other instances, picking needs to be reset with pick all, and upon picking all, the isolation of the instance we are trying to check is lost.

  • I tried oosyrag's idea to remove the instances with the most overlaps first, and it seems to work alright. I used a detector sprite instead of a family but the family idea would work too.

    dropbox.com/scl/fi/jfsdmagr637wr6kqq7jgj/remove_most_overlaps.c3p

    Another idea could be to utilize blue noise to place the objects with a more uniform spacing.

    dropbox.com/scl/fi/tvgd8synoq75c9bsamdfw/blue_noise.c3p

    Here's a comparison of the two.

    Another idea to try is to place the objects randomly and push the overlapping objects away from each other.

    Also the Likely reason why jwilkins' events weren't working when he copied them into a function has to do with quirks regarding picking with newly created objects. Basically created objects aren't generally pickable till the next non-nested event runs. So usually we create all the objects in bulk in one event and manipulate them in the next if we can to work around it.

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