Topic was automatically imported from the old Question2Answer platform.
Asked By
010vince
Hi everyone,
I’m trying to make a 2d platform shooter and I have an enemy which shoots bullets if the player is within range. If the player shoots the enemy, it dies and has a few frames of death animation. Now during the death animation the enemy keeps firing bullets and I can’t figure out how to stop this during these few frames.
It’s hard to provide a detailed answer without seeing your code. That said, you probably just need a simple boolean variable to indicate when the enemy has been killed. At the point where you know the enemy has been shot, set the variable. Then, in the enemy’s shooting code, only shoot if that variable isn’t set…
Having no idea what your code looks like, here’s a mock-up…
var enemy_dead = false # enemy not dead by default
_on_enemy_area_entered(area):
if area.is_in_group("bullet"): # enemy hit by bullet
enemy_dead = true # set the enemy_dead boolean
$EnemyAnimation.play("death") # play the enemy death animation
enemy_shoot():
if !enemy_dead: # if the enemy hasn't been flagged as "dead", shoot
shoot()
Thank you so much, this totally worked! I was thinking way too complicated and didn’t put my enemy_dead variable in the enemy_shoot function haha, makes so much sense now that I think about it!
Thank you!