This is my second attempt at making a 2d platformer. I was following Brackey’s tutorial the first time, which went relatively smoothly. I tried to recreate it on my own with only the code, but now there’s something wrong. Whenever the character falls off a platform and into the void, instead of dying and restarting at the beginning of the level, you can still control the character from below the camera.
That’s the definition of the function, but there’s no call to it. I guess you connected the signal, but are you sure it gets called? You could set a breakpoint or just use a print message inside _on_timer_timeout().
You’re using an Area2D for death detection, which is fine, but you’re freeing the player’s CollisionShape2D before the scene reload. This could be causing the issue where the player remains controllable. The approach of freeing the collision shape might be interrupting the proper death sequence.
extends Area2D
@onready var timer = $Timer
func _on_body_entered(body) -> void:
if body.is_in_group("player"): # Make sure we're only affecting the player
print("You died!")
# Disable player input instead of removing collision
body.set_process_input(false)
body.set_physics_process(false)
Engine.time_scale = 5
timer.start()
func _on_timer_timeout() -> void:
Engine.time_scale = 1
get_tree().reload_current_scene()
Make sure your Area2D is wide enough to catch the player no matter where they fall and Instead of removing the collision shape you might want to disable player input