Script attached to Camera2D:
extends Camera2D
var zoomSpeed: float = 0.05
var zoomMin: float = 0.001
var zoomMax: float = 2.0
var dragSensitivity: float = 1.0
func _ready():
zoom = Vector2(1,1)
func _input(event):
if event is InputEventMouseMotion and Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
position -= event.relative * dragSensitivity / zoom
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoom += Vector2(zoomSpeed, zoomSpeed)
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom -= Vector2(zoomSpeed, zoomSpeed)
zoom = clamp(zoom, Vector2(zoomMin, zoomMin), Vector2(zoomMax, zoomMax))
I was following a tutorial and this is supposed to stop me from zooming out too far, but it does nothing. When i zoom out too far i get this error:
"E 0:00:02:0140 Camera2D.gd:20 @ _input(): Zoom level must be different from 0 (can be negative).
<C++ Error> Condition “Math::is_zero_approx(p_zoom.x) || Math::is_zero_approx(p_zoom.y)” is true.
<C++ Source> scene/2d/camera_2d.cpp:83 @ set_zoom()
Camera2D.gd:20 @ _input()
"
over and over again.