0 votes

Bullet

func _on_Bullet_body_entered(body):
if "Enemy" in body.name:
    body.dead()
queue_free()

Enemy

func dead():
is_dead = true
velocity = Vector2(0,0)
$AnimatedSprite.play("dead")
$CollisionShape2D.set_deferred("disabled",true)
$Timer.start()

I wrote this codes via a tutorial and its actually worked but there is some problems in it. In the video he shoots the enemy and enemy play dead animation, removing his collision and stay on the floor but in my game when i shoot the enemy its falling and doesn't play the dead animation

in Engine by (36 points)

Try changing
If "Enemy" in body.name
To
If body.name == "Enemy"

Same,its still falling down and doesn't play dead animation

1 Answer

0 votes

Maybe it's deleting the body once the animation starts and it's happening so fast it seems like the animation not playing.maybe delete the body once the animation has finished instead

by (163 points)

i dont know how to fix this also in the tutorial everything works and is there a any solve to falling down from walls

i mean its not freeze when he dies

Ok try removing the queuefree() and see if it works. Then if it does play the animation move the queuefree() to under the timer

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.