How to add a 'death' animation for Dodge the Creeps tutorial? [SOLVED]

:bust_in_silhouette: Reply From: Prokuneo

I GOT IT! I leave it here in case someone else wants to go a little beyond the tutorial

1- Firts, create a variable at startup and declare it false

var is_dead = false

2.- Declare it at the beginning of func _process(delta): as a false condition, so that it is alive and can move (and move the rest of the _process → to be inside of “if is_dead == false”

func _process(delta):
… if is dead == false:
… var velocity = Vector2()
… if Input.is_action_pressed(“ui_right”):
… velocity.x += 1
etc etc… etc…

3.- Add this lines at func _on_Player_body_entered(_body): that specifies what to do when the players dies:

func _on_Player_body_entered(_body):
… var velocity = Vector2() #to call states of movements #NEW
… is_dead = true #to declare that… is not live… duh #NEW
… velocity = Vector2(0, 0) #to make him stop #NEW

… $CollisionShape2D.set_deferred(“disabled”, true)
… emit_signal(“hit”)
… $AnimatedSprite.play(“death”) #to play your animated sprite for death for the player #NEW
… yield($AnimatedSprite, “animation_finished”) #to hold the next “hide” until the death animation is finished #NEW

… hide()

4.- Make him life again at the beginning of the function start:

func start(pos):

… is_dead = false #New
… position = pos
… show()
… $CollisionShape2D.disabled = false

Glad that you solved it.

Ertain | 2021-11-09 21:55