Coordinate issues(I guess)

Godot Version

4.2.2

Question

I’m new to godot and as my first project i’m trying to do a really simple pong type of game, and I’m facing some issues about placement of a ball. Please don’t mind the chaotic code. (It’s not finished yet)

var speed: int
var accel = 30
var dir: Vector2
var screen_size

func _ready():
screen_size = get_viewport_rect().size

make_ball()

func _physics_process(delta):
move_and_collide(speed * dir * delta)

func make_ball():
speed = 250
position = Vector2(screen_size.x / 2, screen_size.y / 2)
print("Ball position: ", position) # (576,324)
random_dir()

func random_dir():
var dir_arr = [1,-1]
dir.x = dir_arr.pick_random()
dir.y = dir_arr.pick_random()
dir = dir.normalized()

My issue here is that the ball isn’t spawning at the center of small-windowed game screen (the ball is made with Color Rect). I think that the code has no issues that could cause the ball to spawn outside of game window. It might sound weird but I believe that the Godot itself somehow caused the problem and here’s why: when I was writing script for the paddles I firstly used “clamp”. As a min value, I set 0 (top of the window) and the game was stopping the paddle not at the top of game window, but somewhere in the middle of window.
Whatever the issue is, I have no clue what to do and how to fix it. Please help

Do you have a camera in the Scene? It may be centered instead of aligned to the top-left.

I didn’t have one. I tried adding one after your reply and same thing happens. After that I created new project with exactly the same script and nothing changed, untill I divided the screen_size cord by 6 (192, 108) and it made the ball spawn somewhere in the middle. I still don’t know why in-game cords are so different from the “on-scene” cords