How can reload a current scene if my player die without affecting enemy character

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Allen_Monzon

I can’t figure to respawn a player because if I kill my enemy it gets reload_current scene but I want is if my player die that reload happen…How can you respawn your character without affecting your enemy using get_tree().reload_current_scene.?

:bust_in_silhouette: Reply From: Juxxec

You have two options:

  • Option 1: Don’t use get_tree().reload_current_scene(). Instead, play a death animation and after the animation is done, just move the Player to the starting position for the level (along with the camera).

Create a Position2D node that marks the spot, where the player should start from. In your code, once the player dies:

func die():
    yield($AnimationPlayer, "animation_finished")
    self.global_position = get_node("%SpawnPosition").global_position