0 votes

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.

asked Jun 20 in Engine by 010vince (15 points)

1 Answer

+1 vote
Best answer

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()
answered Jun 20 by jgodfrey (5,574 points)
selected Jun 21 by 010vince

Thank you so much, this totally worked! I was thinking way too complicated and didn't put my enemydead variable in the enemyshoot function haha, makes so much sense now that I think about it!
Thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.