In case it helps, even though it's not VisualScript(it's GDScript), I did write this for one of my own things:
extends Node2D
var motion = Vector2()
const still = Vector2(0, 0)
func _input(event):
if event is InputEventMouseMotion:
motion = event.relative
if event is InputEventMouse:
var cam = get_node("CameraPosition/Camera2D")
if event.is_action("action_left"):
if event.is_pressed():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if event.is_action_pressed("action_zoom_in"):
if cam.zoom >= Vector2(2, 2):
cam.zoom -= Vector2(1, 1)
if event.is_action_pressed("action_zoom_out"):
if cam.zoom < Vector2(3, 3):
cam.zoom += Vector2(1, 1)
func _physics_process(delta):
var speed = 256 * delta
var cam_pos = get_node("CameraPosition")
if Input.is_action_pressed("action_left"):
if motion.abs() != still:
cam_pos.translate(-motion * speed)
motion = still #Do not forget to reset your frame-time variables!
action_left is created and set to left mouse button from project setting - input map.
action_zoom_in and action_zoom_out were created the same way, but respectively mapped to scroll wheel up and down.
The scene consists of 3 nodes: Node2D named as CameraController, then under that a Position2D named as CameraPosition and finally parented to that in turn is the Camera2D node, no name change there. Script attaches to the CameraController and once saved the scene can be instanced into your game scene in turn.
Instead of creating a LMB action_left you'll likely want to create a middle mouse button mapping for PC platforms and maybe create a whole separate script for mobile/console ports off of this. As it stands the action_left hides the mouse cursor via MOUSE_MODE_CAPTURED and that is the case even if clicking on say a GUI element like a button.