How to make camera movement with middle mouse button?

Godot Version



How to make 2d camera moving with middle mouse button like in warcraft 3 or Dota 2, when you hold MMB and when you drag in down, it goes up, when you drag it right, it goes left, etc?

1 Like

just the usual input mouse button with the button index of middle mouse button

I know how to input mouse button, but how to write in code so my camera2d node in game would move like I described

@onready var camera=$Camera2D

var pivot_camera=Vector2.ZERO

func _physics_process(delta):
	if Input.is_action_just_pressed("grab_camera"):
	if Input.is_action_pressed("grab_camera"):
		var gap=pivot_camera-get_global_mouse_position()

the grab_camera in InputMap:

if you want it to go back to original position, just set it from input action just released and set the camera offset again to Vector2.ZERO value

It worked, thanks!

1 Like