Y position 0 below top of window

Godot Version

4.5

Question

Hi everyone, I have a little bird spite controlled by the player that I want to die if it hits the top or bottom of the window. to do this I have a simple if statement in the _physics_process() function to check the sprites position and compare to the window size.

    #the player dies if they go to far above or below the window area
    if to_global($BirdSprite.get_rect().position).y > Global.win_size.y or to_global($BirdSprite.get_rect().position).y < 0:#-(sprite_size.y + 10):
        print(to_global($BirdSprite.get_rect().position).y)
        print($BirdSprite.get_rect().position.y)
        print('death')#death_animation()
        get_tree().reload_current_scene()

This works fine for the bottom of the window but for the top the bird dies before ever hitting the top of the window and when I check the birds position with a print statement it give the number I would expect if it were actually at the top (about -1). So my question is why is the windows 0 y position registering below the actual top of the visible window.

Thanks in advance.

Check the position of the sprite in respect to character body’s origin.

OK So this was just a logic error on my part. After some debugging I found that there were two problems with what I was doing. The first was that at some point I had set the Sprites position in the inspector to (42, 42) but I was writing the code with the assumption that it was still at (0, 0). The other problem was that I was using get_rect to check the bounding box which was completely unnecessary and a needlessly complicated way to get the sprites position. So I reset the spites origin back to (0, 0) and removed all calls to get_rect and it now works perfectly.

Thank you @normalized for your replay. I set me on the right track