Stop enemy from shooting while death animation plays

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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.

Please help me folks, you’re my only hope.

:bust_in_silhouette: Reply From: jgodfrey

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

    if area.is_in_group("bullet"):    # enemy hit by bullet
        enemy_dead = true       # set the enemy_dead boolean
        $"death") # play the enemy death animation

    if !enemy_dead: # if the enemy hasn't been flagged as "dead", 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!

010vince | 2020-06-21 06:30