Clamping Vector2 does not work on zero

Godot Version

4.2.2

Question

I am using a Camera2D node and implementing a zoom function.
I also implement a min and max zoom using the Vector2.clamp method.
It does clamp as Vector2(2,2) but it does not for Vector2(0,0) or Vector2.ZERO and goes beyond the negative side which inverts the view.
Why does it not clamp on zero? Here is my code:

var cameraZoom = Input.get_axis("WHEEL_UP", "WHEEL_DOWN")
zoom += zoomSpeed * cameraZoom
zoom = zoom.clamp(Vector2(0,0), Vector2(2,2))

Seems like camera zoom can’t be 0, set it to something like 0.1(or something even lower). see if this fixes it.

Note: default zoom is 1

1 Like