Help with respawning system

Godot Version



I am new to godot and working on a respawning system for my game. For some reason, whenever the player dies, they respawn really far away from the checkpoint. Here is my code:

Checkpoint code:

extends Area2D

func _on_body_entered(_body):
	$"Ambient particles".emitting = false
	$"Explode".emitting = true
	$"Sprite2D".texture = load("res://Assets/Other/checkpoint closed.png")

func _on_timer_timeout():

Player code (may need to scroll):

extends RigidBody2D

@export var speed = 40
var respawn_location: Vector2

func _ready():

func _physics_process(delta):
	if Input.is_action_pressed("Move right"):
		angular_velocity += speed * delta
	if Input.is_action_pressed("Move left"):
		angular_velocity -= speed * delta

func jump_pad():
	linear_velocity.y = -800

func respawn():
	linear_velocity = Vector2.ZERO
	angular_velocity = 0
	position = respawn_location

func checkpoint():
	respawn_location = position

Killzone code:

extends Area2D

@onready var timer = $Timer
var player

func _on_body_entered(body):
	player = body

func _on_timer_timeout():

Not understand properly, please upload the full project removing you secrets or game idea

Here is a stripped down version of the project:

Occasionally when you die, you will fail to respawn.
You may need to die a few times to see the bug.

1 Like

I am trying to fix it

First, when I not reach in checkpoint, I fall down for test, then I spawn in air I means in wrong position, to fix it replace this code var respawn_location: Vector2 with this correct code var respawn_location: Vector2 = Vector2(4861, 103-10), second…, let me know if its working then I will mention the second problem…

Second, I see, you created a big mistake, to fix it

  1. Add a variable in Singleton, “checkpoint_reached = false”
  2. In, replace your codes checkpoint function with:
func checkpoint():
	if Singleton.checkpoint_reached: return
	respawn_location = position
	Singleton.checkpoint_reached = true
  1. In, replace the respawn function with this correct codes:
func respawn():
    if Singleton.checkpoint_reached:
        respawn_location = Vector2(5010.683, 124.0556-25)
        respawn_location = Vector2(4861, 103-10)

    linear_velocity = Vector2.ZERO
    angular_velocity = 0
    position = respawn_location
  1. Don`t forget to add this code in the
var respawn_location: Vector2 = Vector2(4861, 103-10)
  1. Let me know if its works?
  2. If you suffers with adding more checkpoint, you can tell me I will help you
  3. What is the big glitch/mistake you made? as you mentioned the respawn position (5010.683, 124.0556), the y axis is underground, so its the collision problem so I substract the y axis with 25 means upper position than the ground
1 Like


1 Like

@KingGD Is there any chance you could help me with the other issue I’m having?

Ok, I will try it.