Clamp and screen window mismatch

Godot Version

4.3

Question

Hey everyone,

I am having an problem with clamping. The borders that it creates arent in line with the screen windows it shows. I am having this issue while trying to learn the "your first 2d game documentation from godot itself.


This is the top left corner the border creates.


This is the starting point of my character.


Picture of the 2d scene i am working in

I have tried many changes int the code already that i could find but nothing seems to work.

extends Area2D

@export var speed = 400 #Snelheid van de speler #Pixels per seconde
var screen_size 
var character_size

func _ready():
	screen_size = get_viewport_rect().size
	position = screen_size / 2
	character_size = $CollisionShape2D.shape.get_rect().size

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	var velocity = Vector2.ZERO 
	if Input.is_action_pressed("move_right"):
		velocity.x += 1
	if Input.is_action_pressed("move_left"):
		velocity.x -= 1
	if Input.is_action_pressed("move_up"):
		velocity.y -= 1
	if Input.is_action_pressed("move_down"):
		velocity.y += 1

	if velocity.length() > 0:
		velocity = velocity.normalized() * speed
		$AnimatedSprite2D.play()
	else:
		$AnimatedSprite2D.stop()
	
	position += velocity * delta
	position = position.clamp(Vector2.ZERO + character_size / 2, screen_size - character_size / 2)