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:
emitsignal: Error calling method from signal 'animationfinished': 'KinematicBody2D(Enemy.gd)::onAnimatedSpriteanimationfinished': Method not found..
This is the enemy script:
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
motion.x = clamp(motion.x, -stats.speed, stats.speed)
if is_dead == false:
if player.position.x > position.x:
motion.x = stats.acceleration
animsprite.scale.x = 1
elif player.position.x < position.x:
motion.x = -stats.acceleration
animsprite.scale.x = -1
motion.x = lerp(motion.x, 0,0.2)
motion.y += GRAVITY
motion = move_and_slide(motion, UP)
stats.health -= area.damage
motion.x = 0
is_dead = true
Im sure the problem has something to do with the "onStatsnohealth():" 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!