Trouble with y axis position while moving camera2D

Hi, I´m completly new to programming making my first steps with Godot.
Sorry to bother with something super basic, but it’s puzzling me and i just want to know what it’s happening.

I’m setting up a Camera2D that you can move with the WASD keys. I set up the limits in the inspector, and while the view stops at the limit the node keeps moving beyond, so i thought about changing the position of the camera when it goes beyond the limit, so that there is no delay turning back.
It works perfectly on the X axis, but when implementing the same on the Y axis, it doesn’t work and i can’t figure it out.

func _process(delta):
	if Input.is_action_pressed("Up"):
	if Input.is_action_pressed("Down"):
	if Input.is_action_pressed("Left"):
	if Input.is_action_pressed("Right"):
	if position < Vector2(187,0):
		position.x = (187)
	if position > Vector2(953,0):  		
		position.x = (953)
         if position <  Vector2(0,107):
		position.y = (107)
	if position > Vector2(0,530):
		position.y = (530)

The camera position starts at (576, 324).
Why the position.x lines work as intended, but the position.y doesn’t? The last lines even lock the y at 530, unable to move it.
I thought maybe i should use global_position, but its the same.
Thanks for your help.

better set the camera offset than the camera position itself

I’ll look into that, thanks, but why the code doesn’t work?

In the last lines , 324 > 530 should be false, but it returns true for some reason.

Unless (0,530) is being read as a float? But i don’t know how that would be possible either.

you actually can clamp the position without having to check with if like you did

also if you are using position, you can set the limit of how much the camera can go

Yes, i did set those limits, and while they work with the view of the camera, they do not work with the actual Camera2D node that i’m moving with the input keys.

For example, if i move the camera to the left and keep pressing left, the camera will stop at the the limit but the position of the camera node will keep traveling left. If i then start pressing right, the camera will not move until the position of the node reaches inside the limit and only then it start moving right.

It’s that delay that i’m trying to fix with respawning the postion back at the limit. And i works perfectly on the X axis, but not on the Y for some reason.

extends Camera2D

@export var player_node:Node

const MAX_POS=50.0
const MIN_POS=-50.0

var current_pivot_position
var is_camera_moving:bool=false
var input=Vector2.ZERO

func get_input():
	return input.normalized()

func _process(delta):
	if input==Vector2.ZERO and not Input.is_action_pressed("Right") and not Input.is_action_pressed("Down"):
		if not is_camera_moving:

remember to assign the player node
also put this camera as a child of the player

Also check this out, moving camera with middle mouse button grab:

Thanks for yor reply, i 'll check it out, but there is no player, or playercharacter. It’s just the invisible camera node movement with the WASD keys. If i could assign the camera to a player i could also work with collisions, but i can’t.

Even if i could find a solution for the camera limits, i would still like to know why my inital code doesn’t work, or more specifically how it works on one axis and not on the other. Where is the mistake?