Welcome to the forums @Eddu52!
I'd suggest using the clamp
function to keep the zoom in the bounds you want. Something like this:
func _zoom_camera(dir):
zoom.x = clamp(zoom.x + dir, 0.2, 2.0)
zoom.y = clamp(zoom.y + dir, 0.2, 2.0)
# optimization, since the zoom is uniform, you can skip
# the second clamp and just use
# zoom.y = zoom.x
# instead.
The issue you are having is that when the zoom is outside of the given range, you are not applying the dir
offset to it, but since you are not applying the dir
offset, you cannot get the zoom back into range either. You could also apply the direction, and then use two if conditions and constrain as required:
func _zoom_camera(dir):
zoom += Vector2(0.1, 0,1) * dir
# since the zoom is uniform, we only need to check the x or y, but not both
if (zoom.x < 0.2):
zoom = Vector2(0.2, 0.2)
elif (zoom.x > 2.0):
zoom = Vector2(2.0, 2.0)