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.
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
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.
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
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.
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.