Pushing a Line of Enemies-Identical Object Overlap

0 favourites
  • 5 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • I'm working on a 2D action game. I have multiple of the same enemy type on the screen at once. We'll call it "enemy1." The player cannot pass through enemy1 and enemy1 cannot pass through other enemy1s. When the player strikes this enemy it is pushed backward. When enemy1 is pushed into a long line of enemy1s, it sort of pops into a random spot in line and another enemy1 pops in the front of the line. I want it to push the full line of enemies rather than one trying to force its way past the rest.

    If that's confusing imagine a line of Goombas in Super Mario and imagine hitting a Goomba with a shell knocks it backward instead of killing it.

    Mario kicks a shell into a line of 10 Goombas.

    M>S>>   1 2 3 4 5 6 7 8 9 10

    M   >S>>1 2 3 4 5 6 7 8 9 10

    Rather than pushing the entire line back, Goomba 1 pops backward in front of Goomba 7. Goomba 2 is now in goomba 1's position.

    M   2 3 4 5 6 >>1 7 8 9 10

    I want the whole line of Goombas to push backward when the first is hit with a shell.

    M             >S>1 2 3 4 5 6 7 8 9 10>

    The best I've come up with is to have enemies moving with 8-Direction, the "push" happens as a custom movement on a player strike. The enemy is solid to keep them from passing through each other.

    The difficulty for me is having to reference the same object when checking for overlap. For example, setting enemy1's X position to enemy1.x-10 on overlap of enemy1 causes jittery chain reactions. Making enemy1 solid is the only workaround I can come up with, but weird things happen when multiple solids collide.

    I found this post but it makes no sense to me (create a family with only object objects???):


    Thank you!

  • If they're all identical enemies why does it matter which order they are in? How can the user tell ?

  • A fake, invisible grid... Grid is registered and updated on an array. Each enemy is registered in one of the grid squares, always updated. When enemy is pushed, do the magic math on the array to "move" their places in the array, and update the positions accordingly.

    Just on the top of my head. There may visually be problems, like enemies pushing eachther even though they are not touching eachother... Or different sizes of enemies may cause problems... But maybe this will give ideas?

    Sorry if it was too vauge. Not good with changing ideas into language.

  • The user can tell because the enemies have 3 hit points. It also looks sloppy visually when the enemies are making sudden, jerky movements to make room in the line. If it happened smoothly I wouldn't have anything to complain about.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I haven't tried it yet, but I imagine an array will have similar problems assigning values to specific instances. You may be going somewheres with the grid. They're ghastly enemies so grid-based movement wouldn't be uncharacteristic, but I'd hate to invest a lot of time in such a small mechanic.

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