How do two objects dont spawn in the same place?

0 favourites
  • 5 posts
From the Asset Store
Spooky Places game assets for 2D endless runner action adventure game.
  • In the minigame I am generating objects randomly all over the surface, what I want to do is that they do not overlap each other and end up all mounted; is there a way to make it simple, I have tried a thousand ways and I can't think how to make it work.

    That is to say that object X does not overlap with object Y in the same position.

    Thanks

    This is what happend i dont wanna.

  • I am not saying this is the best method to use but the way I would do it in my game is to create the object, then check if it is overlapping an object - if true then destroy it and create the object again. You would repeat this until the overlap check is false.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I use 2 different ways:

    Lionz answer is the first route - it works great as long as there is enough room for the objects to spawn and find a place without having to retry over and over. Your 11 targets would take up quite a lot of the overall screen space meaning you would potentially experience issues finding a place for the last few targets every now and then.

    route 2 - Preplace sprites set to invisible everywhere on the screen you would be okay with a target appearing (AKA spaced so they won't overlap). Give each of these sprites a boolean to track 'tracker' if you used it - starting value: false.

    For each sprite & tracker = false & Pick Random sprite - Create Target sprite.x,sprite.y and set tracker to True.

  • I try to create with your ideas. The bad side its if i destroy the Bullseye with the plus or the cross i have count errors and less points.

  • I usually put a cool down at the spawn point.

    If it already spawned, start cool down timer, until it is zero, it can spawn again.

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