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.

in Engine by (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

    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

    if !enemy_dead: # if the enemy hasn't been flagged as "dead", shoot
by (21,732 points)
selected by

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.