how do i fix the killzone

Godot Version

v4.6.1

Question

I am a noob and I just followed a yt tutorial and changed a couple things. the problem is that the chracaterbody just falls down and ignores the collision of the area2d. Currently using v4.6.1

extends CharacterBody2D

class_name Player

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

func respwan():
	self.global_position == Vector2(1,0)

	
func _physics_process(delta: float) -> void:
	if not is_on_floor():
		velocity += get_gravity() * delta
		if Input.is_action_pressed("ui_right"):
			$AnimatedSprite2D.play("walk")
		if Input.is_action_pressed("ui_left"):
			$AnimatedSprite2D.play("walkleft")

	# 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
		if Input.is_action_pressed("ui_right"):
			$AnimatedSprite2D.play("walk")
		if Input.is_action_pressed("ui_left"):
			$AnimatedSprite2D.play("walkleft")
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		$AnimatedSprite2D.play("idle")
	
	
	move_and_slide()

extends Area2D

func _on_body_entered(body) → void:
if body.name == “Player”:
body.respawn()
monitoring = true

1 - area2D is calling body.respawn, but in character it’s called respwan
this should be throwing errors in red, which you should’ve noticed.

2 - this code also relies on your player being called exactly "Player", which would explain why it’s would not be throwing errors. It’s not a good way to do it.
you can put the player on a group and then check if it’s on that group, or check if it has a function with has_method

if body.has_method("respawn"):
	body.respawn()
2 Likes