How do I make my platformer enemies attack correctly?

0 favourites
  • 4 posts
From the Asset Store
10 Retro songs ideal for platformers or farming games
  • Hi everybody. I'm pretty much brand new to Construct 2 and am working my way through a platformer. I've run up against a snag with some of my enemy behavior. My enemies patrol over a set distance, turning when they collide with an invisible "detector sprite." No problems there.

    When they're on collision with the player, I want them to go into an attack mode were a few things happen:

    1) The enemy stops moving forward.

    2) The enemy's animation changes to an attack animation.

    3) The player's acceleration and jump strength is reduced, slowing him down.

    4) For every 1.5 seconds that the player remains "under attack," his health is reduced.

    5) Once the player gets away, everything goes back to normal.

    This is what I've been able to work out so far:

    [attachment=0:18ymk74s][/attachment:18ymk74s]

    Undoubtedly, there's a more elegant and efficient way to do this, so I am gladly open to any and all suggestions, but the big problem is that this works just fine, but only with the oldest instance of the enemy in the layout. On collision with any other enemy, there is absolutely no effect. If the oldest enemy instance is destroyed, then the attack actions work with the next instance, and so on.

    I've looked through the manual and the forums and tutorials and can't, for the life of me, figure out what I'm doing wrong and why the attack actions only trigger for one enemy in the layout at a time.

    Any help would be MUCH appreciated!

  • You need a boolean for the enemy too, it doesn't know if it has to attack or not. Add a true/false for the enemy and put the animations/platform input events to the respective condition.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That seems to have done the trick. Many thanks! I had tried this earlier, but must not have had everything organized correctly, because it didn't seem to be working. Now it's working like a champ! I also changed it so that the attack triggered while the two sprites were overlapping, rather than on collision. I think that was part of the problem as well.

    Again, many many thanks!

  • You're welcomed, you seem to be understanding the logic/event system nicely. Keep it up and you'll see what awesome stuff you can cook. I'm still learning everyday.

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