Help With Zoom Issue in Plugin

Godot Version

4.3 Dev 3

Question

Can someone that knows more then I do tell me if this issue is related to Godot or with the Godot Touch Input Manager? I have provided what I can within the plugins GitHub Issues section here.

Thank you in advance :slight_smile:

Hi, To zoom with two fingers or move the camera (Pan) you can use this code. It is taken from a YouTube tutorial. No plugin is needed.
I hope this is what you are looking for.

extends Camera2D

export var zoom_speed: float = 0.1
export var pan_speed: float = 1.0

export var can_pan: bool
export var can_zoom: bool

var touch_points: Dictionary = {}
var start_distance
var start_zoom
# Declare member variables here. Examples:
# var a = 2
# var b = "text"I hope this is what you are looking for.
# Called when the node enters the scene tree for the first time.
func _ready():
	pass
func _input(event):
	var ACTIVE = GET_ACTIVE_ZOOM_OR_PAN = (true or false)
	if ACTIVE:
		if event is InputEventScreenTouch:
			handle_touch(event)
		elif event is InputEventScreenDrag:
			handle_drag(event)
			pass
	
func handle_touch(event: InputEventScreenTouch):
	if event.pressed:
		touch_points[event.index] = event.position
	else:
		touch_points.erase(event.index)
	
	if touch_points.size() == 2:
		var touch_point_positions = touch_points.values()
		start_distance = touch_point_positions[0].distance_to(touch_point_positions[1])
		start_zoom = zoom
	elif touch_points.size() < 2:
		start_distance = 0
		
func handle_drag(event: InputEventScreenDrag):
	touch_points[event.index] = event.position
	
	if touch_points.size() == 1:
		#print("OF",offset.x)
		if can_pan:
			#if offset.x <= 1000 or offset.x >= -2000:
			offset -= event.relative.rotated(rotation) * pan_speed

	elif touch_points.size() == 2:
		var touch_point_positions = touch_points.values()
		var current_dist = touch_point_positions[0].distance_to(touch_point_positions[1])
		var zoom_factor = start_distance / current_dist
		
		if can_zoom:
			zoom = start_zoom / zoom_factor
		
		limit_zoom(zoom)

func limit_zoom(new_zoom):
	if new_zoom.x < 0.1:
		zoom.x = 0.1
	if new_zoom.y < 0.1:
		zoom.y = 0.1
	if new_zoom.x > 10:
		zoom.x = 10
	if new_zoom.y > 10:
		zoom.y = 10	
1 Like

@mmicoe thank you for your response. I will see if this code will either work with or replace some of the current pluginโ€™s code for this function. I would like to try and fix the plugin itself if possible simply because others that use the plugin from the asset store will benefit.

Do you happen to have a reference to the YouTube video?

Hi, yes of course:

All the best!

1 Like

Oh yeah, FinePointCGI he has some pretty good tutorials, thank you again for sharing it with me. I really appreciate it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.