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:
extends RigidBody2D
@export var speed = 40
var respawn_location: Vector2
func _ready():
Singleton.jump_pad.connect(jump_pad)
Singleton.respawn_player.connect(respawn)
Singleton.checkpoint.connect(checkpoint)
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
timer.start()
func _on_timer_timeout():
Singleton.emit_signal("respawn_player")
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…
var respawn_location: Vector2 = Vector2(4861, 103-10)
Let me know if its works?
If you suffers with adding more checkpoint, you can tell me I will help you
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