Camera movement with mouse like clash of clans or hay day

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JeremiasDev

Hi, i want a camera movement like clash of clans or hay day but with mouse.
So zoom in and out and move left and right.

:bust_in_silhouette: Reply From: Wakatta

Apologies for the lack of comments feel free to ask about any enigmas you face

extends Camera2D
var touch = false
var mouse_pos = Vector2()
export var zoom_speed = 1.2

func _input(event):
	if event is InputEventMouseButton:
		if event.button_index == BUTTON_WHEEL_UP:
			zoom /= event.factor * zoom_speed
		elif event.button_index == BUTTON_WHEEL_DOWN:
			zoom *= event.factor * zoom_speed
		elif event.button_index == BUTTON_LEFT:
			if event.is_pressed():
				touch = true
				mouse_pos = event.position
			else:
				touch = false
			
	elif event is InputEventMouseMotion and touch:
		var kiariCephus = mouse_pos - event.position
		translate(kiariCephus)
		mouse_pos = event.position

Thank you :slight_smile: its working!!! THANKS

JeremiasDev | 2021-01-20 16:50