Godot Version
Godot Engine v4.3.stable.official [77dcf97d8]
Question
I am trying to move the camera by holding down the middle mouse button. Below is the code I have so far, but it is not working. Keep in mind, I already have the key defined in the Input map. Below is the code I have so far, I would appreciate feedback, thanks.
extends Camera2D
var dragStartMousePos = Vector2.ZERO
var dragStartCameraPos = Vector2.ZERO
var isDragging : bool = false
#Pan camera with mouse wheel button
func ClickAndDrag():
if !isDragging and Input.is_action_pressed(“camera_pan”):
dragStartMousePos = get_viewport().get_mouse_position()
dragStartCameraPos = position
isDragging = true
if isDragging and Input.is_action_pressed("camera_pan"):
isDragging = false
if isDragging:
var moveVector = get_viewport().get_mouse_position() - dragStartMousePos
position = dragStartCameraPos - moveVector * 1/zoom.x