Checkpoints in 2D platformer

Godot Version

Godot 4.2 version

Question

I am trying to make a checkpoint system and im struggling with the code there isnt any tutorial video that i found that works well with my game and i dont understand how it works i need help with the script as well

I don’t know, is it the most optimal way to do checkpoints, but in my game I have created such a system:

  1. I have created a global script, so I can reach it from any another script. (If you don’t know what it is, just google it)
  2. In this global script is a Vector2 variable last_checkpoint
  3. I have created a new scene Area2D for checkpoint, which has a Sprite2D (just an image of checkpoint) and CollisionShape2D.
  4. I have created a code for this checkpoint scene in which I have connected a signal body_entered(body: Node2D).
  5. in the appeared function I have such code:
Global.last_checkpoint = self.position #set the last checkpoint position in global script as the current checkpoint position
queue_free() #delete current checkpoint
  1. In you players code use Global.last_checkpoint to set a respawn position

You mean an autoload by global script, right?

Yes, you are right