How do I add a checkpoint system so each time I die i go to the checkpoint.

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

I am making a platformer and I want to add a checkpoint system so you will restart the level. How do I do that?

:bust_in_silhouette: Reply From: kidscancode

Give the player a variable to record its start point:

var spawn_point = Vector2(100, 100) # coordinates of your initial spawn point

Make an Area2D where you want the checkpoint to be. You can use a rectangle or circle shape - whatever you prefer. Connect the area’s body_entered signal and use this to set the player’s spawn point:

func _on_Area2D_body_entered(body):
    if == 'Player':
        body.spawn_point = position # using the Area2D's position

Now your player can reset itself to the spawn point whenever it dies:

if health <= 0:
    position = spawn_point
    health = 100 # or whatever