Stop interruption of animation of enemy death

I have shooting in my game and when the enemy health hits zero it plays his death animation and deletes the enemy. However, if you continue to shoot at the enemy during his death animation, the animation restarts over and over again.
I don’t have 2d physics behavior on enemies, since it does weird stuff in gameplay. But even when I add 2D physics I’m still not able to disable collision to stop this problem.

How do I…

So my question is how do I prevent the death animation from being interrupted with additional attacks from the player?

I just want the enemy to die without any additional effect from the player.

What is the expected result

When the enemy goes into his death animation, the player can’t interrupt this.

What is the actual result

The player can shoot over and over again at the enemy death animation and it will start over and over again.

Related screenshots

Project files (optional)

Insert a minimal game showing your issue in a .zip or .rar.

Use a Finite State Machine (FSM). You can then have a game state of “death” and not process any player key presses while in that state.

2 Likes

I agree with MrMen but an even simpler way can be to just add

If enemy animation **IS NOT** "death"

Over the whole enemy’s damage mechanic. But it’s your choice on the way you choose to design your game

1 Like

Hi all!

I agree with you but it’s the kind of things that need to be planned before to write anything.
Otherwise, you will have to change later several things in your game and this may not be pleasant.
Personally, i use an object variable when the player id dead (state_player = “dead”). After, i test the value of this variable to know if the player is dead or not

A+
Xierra

Sorry I should have clarified. I do have a Finite State Machine.

And I figured out a solution based upon your comments. Thank you!
Basically on the damage check I just added an inverted & clause condition.

You should really change those numbers to strings/text so it’s easier to understand the state each enemy is in. But more importantly, if the player can constantly hit the enemy and reset its animation, then the enemy doesn’t have enough states and isn’t changing as soon as they’re dead.

Also, those events can be better programmed. You should really be checking the value of the enemy state and then, as a sub event, repeat for each enemy.

1 Like

You don’t need that explicit “If all of these conditions are true”. All the conditions in the event need to be true before the actions are processed.

1 Like

Thank you for the suggestions. So I should add more states? I’ve just added states when I felt behavior/actions were needed. What other states should I add? I’m still really relatively new to all this. Would I add a value check in the main level or under each individual state?

Going by your previous post, I’d say you could do with enemy states “Idle”, “Run”, “Attack”, “Hit” and “Death”.

From idle, the enemy can go to run, attack and hit states.
From run, the enemy can go to attack, idle and hit states.
From attack, the enemy can for to idle, run and hit states.

In those 3 states (idle, run and attack) you’d check if the enemy was hit by a bullet.

From hit, the enemy can go to idle or death states. In hit and death states, the enemy cannot be hit and no checks are made for collision between enemy and bullet.

So all the states for the enemy that I have right now are:
Idle -checks to see if hit by bullet then goes into Hit state
Run -checks to see if hit by bullet then goes into Hit state
Run Shoot -checks to see if hit by bullet then goes into Hit state
Shoot -checks to see if hit by bullet then goes into Hit state
Hit
Death
Detect -checks to see if hit by bullet then goes into Hit state
Spotted -checks to see if hit by bullet then goes into Hit state

What are the events for the hit state?

Just to change the animation. I have the damage being calculated in the main scene event list. Everything else transitions out of Hit. Idle, Death, Shoot, Run.

Are those events in the external event sheet named EnemyHit?

You’re still using numbers for states. It isn’t easy to read.

You don’t need those “If all of these conditions are true” condition. Just move the conditions in them to the main condition part of the event.


Also, with these events:

if the enemy has a health < 0, but the player is in collision with enemy_shootdistance, then the enemy State will get set to 3. The second event will override the first one.

So you need to rethink the game logic. Do something like:

  • Put the health check as the first event.
  • Then create a second event that checks enemy’s health > 0, and put the other 3 events as subevents off the (new) second event.