On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

guys i need help in godot

A topic by The Ungodly God created Feb 15, 2022 Views: 245 Replies: 13
Viewing posts 1 to 8

 how to play the death animation and then kill the enemy. please check my code and help .

func _process(delta):

if health <= 0:

$death_timer.start()

$AnimationPlayer.play("death")

func _on_death_timer_timeout(): # this is a signal timeout

queue_free()

please help

Submitted

Unless the timeout isnt connected to your timer, I'm not really sure why that's not working.  If you want to remove the enemy after the animation plays though you could call the function at the end of the animation in the AnimationPlayer node.

can you check these

(1 edit)

What’s your problem exactly? Is boss just disappearing when it reaches 0?

no it repeats the animation over and over. even though i started the timer. in the timeout function i mentioned queue_free().

(2 edits)

That’s easy. _process function is called every frame so If you reach health==0 your boss dies over and over. The easiest solution is making new variable alive, set it to true by default and then alter your _process function like:

var alive = true

func _process(delta):
  if health <= 0 and alive:
    # Here goes your die code
    $death_timer.start()
    $AnimationPlayer.play("death") 

    alive = false

Now die code triggers only once. Let me know if it works.

(3 edits)

Or you can do it in more elegant fashion by using setter function on health variable.

var health = 100 setget set_health

...

func set_health(value):
  health = value
  if value <= 0:
    die()
...

func on_area_entered(area):
  self.health -= 5. # It's very important to write self.health instead of health if you use setter function
...

func die():
  $death_timer.start()
  $AnimationPlayer.play("death") 
(+1)

thank you very much 

Because of you it's working 


You’re welcome! :)

Submitted(+1)

Kiel brought up a good point I missed, your timer is probably being restarted every frame since the only check is if health is a certain value.  Try adding the alive boolean similar to how they suggested or I'd recommend their second suggestion personally.  Having a function to set the health and just check that when they get hurt instead of all the time is better.

(+1)

Ok Thank you