How do I set a Minimum Distance between all created Sprites of a given type?

0 favourites
  • 3 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hello All,

    I am making a game where roughly every second the System creates a new "enemy" sprite at a certain X coordinate, and a random Y coordinate within a range of points on the Layout. The enemy Sprites are all scrolling to the left at the same horizontal Custom speed. All of the Sprites are part of a Family named "Enemies." I implemented the "Push Out of Solid" action for whenever a member of the Family is overlapping another, and it works fine.

    Here is the issue:

    Each overlapping Sprite pushes out, but it only does so to the very edge of the collision boundary of the Sprite it was previously overlapping. Ultimately, I wind up with a bunch of enemies that are very close to each other, even touching, although not overlapping.

    Here is what I want to do:

    I want to establish a MINIMUM DISTANCE BETWEEN ALL ENEMIES so that there is always room between them. I don't want one enemy right up against another. For example, if you have 100 enemies all running at you from the right of the screen, there should be like 50 pixels between each of the enemies. This is tricky because all of the enemy sprites are being spawned by the System at a random interval between 1 and 2 seconds.

    Here is what I have tried, without success:

    - I tried spawning invisible "hitbox" Sprites pinned to each enemy sprite, but it's too much for the processing and it doesn't work anyway.

    - I tried making it so that after the first enemy Sprite is created by the system, each subsequent enemy Sprite is spawned by the last created one. This creates a chain reaction new Sprites being spawned basically every tick, and it clogs up the processing. Doesn't Work.

    - I tried adding the width of the previously created Sprite to the X coordinate of each newly spawned Sprite, but that doesn't work because it just pushes the congestion problem back a few Sprites like a domino effect.

    -I even tried increasing the canvas size of each enemy Sprite to twice the dimensions of the actual image, meaning the Sprite itself is twice as big as the image, while the collision box is bordering the image. IT DOESN'T WORK!

    Please, somebody's gotta know, how to I establish padding around each and every enemy Sprite, that prevents any of them from butting up against each other? How do I establish a constant and universal minimum distance between all enemies regardless of when and where they spawned?

  • ADDITIONALLY

    I also tried using the "Set Position" action for whenever a given sprite is within a certain distance from the X and Y coordinates of another sprite within the "Enemies" family. It works, but it looks terrible when it sets the position because it appears to skip around. No good.

    I ALSO tried using the "Move To" behavior under the same conditions as stated above, but it looks absolutely ridiculous when the sprites are dancing around and flipping all over the place like drug-addled idiots.

    Please........ please.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Make a bumper sprite that is as big as you want with a round collision (say 8 points in a circle) and make it invisible (or a see through color while debugging perhaps). Attach each enemy to a separate instance of this bumper sprite as a hierarchy. Make the bumper sprite a solid,

    Every tic turn all bumper sprites solid, have them all push out solid in an ordered manner, turn them off solid. The order matters so you don't get flicker as they push first one way and then another. I think the one that is pushing out can't be solid so all but one get turned solid in the loop.

    This kind of thing works for me.

    yours

    winkr7

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