![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | LyguN |
I have a simple enemy script where the enemy follows the player and the player can damage the enemy. I was recently trying to add a death effect with animation to the enemy. I did that and everything works fine except that I get an error-message like every half-second.
The error message is as following:
emit_signal: Error calling method from signal ‘animation_finished’: ‘KinematicBody2D(Enemy.gd)::_on_AnimatedSprite_animation_finished’: Method not found…
This is the enemy script:
extends KinematicBody2D
const GRAVITY = 10
const UP = Vector2(0, -1)
var motion = Vector2()
var is_dead = false
onready var animsprite = $AnimatedSprite
onready var player = get_parent().get_node("Player")
onready var stats = $Stats
func _physics_process(delta):
motion.x = clamp(motion.x, -stats.speed, stats.speed)
if is_dead == false:
if player.position.x > position.x:
motion.x = stats.acceleration
animsprite.play("Skeleton_Walk")
animsprite.scale.x = 1
elif player.position.x < position.x:
motion.x = -stats.acceleration
animsprite.play("Skeleton_Walk")
animsprite.scale.x = -1
else:
motion.x = lerp(motion.x, 0,0.2)
animsprite.play("Skeleton_Idle")
motion.y += GRAVITY
motion = move_and_slide(motion, UP)
func _on_Hurtbox_area_entered(area):
stats.health -= area.damage
func _on_Stats_no_health():
motion.x = 0
is_dead = true
animsprite.play("Skeleton_Death")
yield(animsprite, "animation_finished")
queue_free()
Im sure the problem has something to do with the “_on_Stats_no_health():” function and the “if is_dead == false:” statement because I didn’t get the error message before I added that “if” statement, but then the idle animation would play instead of the death animation when the enemy dies.
I feel like I am missing something simple. Any help is appreciated!