How do I make my platformer enemies attack correctly?

Just started using Construct 2? Post your questions here

Post » Mon Aug 04, 2014 8:19 pm

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:

enemy-attack.jpg


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 do not have the required permissions to view the files attached to this post.
B
7
S
1
G
1
Posts: 5
Reputation: 408

Post » Mon Aug 04, 2014 10:21 pm

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.
B
11
S
2
Posts: 100
Reputation: 1,150

Post » Mon Aug 04, 2014 11:18 pm

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!
B
7
S
1
G
1
Posts: 5
Reputation: 408

Post » Tue Aug 05, 2014 1:27 am

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.
B
11
S
2
Posts: 100
Reputation: 1,150


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests