Godot Version
4.6.2
Question
Hey,
First of all, I’m new to game development, this is my first time using any game engine, and I’m sorry if this is some type of ‘basic’ bug, but I couldn’t find anything.
I’m having a problem - my kill zone doesn’t work. The problem started when the kill zone didn’t register that the player fell into it. I solved it with just coordinates, everything alright. Then I jumped with the player, it killed him constantly and thanks to the console logs, I found out that the kill zone somehow killed him even though it’s more down. Then I jumped on a different place and found out that only first three blocks are the problem and I can’t find the problem.
I will be really grateful if someone would be able to help me.
This is code for the kill zone:
extends Area2D
@onready var timer: Timer = $Timer
func _ready() -> void:
timer.timeout.connect(_on_timer_timeout)
func _on_body_entered(body: Node2D) -> void:
if timer.is_stopped():
print("You died!")
timer.start()
func _on_timer_timeout() -> void:
print("Timer finished! Reloading...")
get_tree().reload_current_scene()
And this is code for the player:
extends CharacterBody2D
const SPEED = 100.0
const JUMP_VELOCITY = -300.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
if global_position.y > 1000:
print("Player fell out of bounds!")
get_tree().reload_current_scene()



