My touch pinch zoom in became zoom out instead, and vice versa

Godot Version

<4.2>

Question

Hello, I tried to make a proper way to zoom in and out using pinch on android device. Everything works fine, but the direction of the zoom is kinda flipped. And I’m quite clueless when dealing with Vector. I just need the zoom-in to be zoom-out instead and vice versa. Here is part of my code.

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 = position
		
	elif  touch_points.size() <2:
			start_distance = 0

func handle_drag(event: InputEventScreenDrag):
	touch_points[event.index] = event.position
	if touch_points.size() == 1:
		if can_pan:
			h_offset -= event.relative.x * pan_speed
			transform.origin.z -= event.relative.y * pan_speed
	elif touch_points.size() == 2:
		var touch_point_positions = touch_points.values()
		var current_distance =  touch_point_positions[0].distance_to(touch_point_positions[1])
		
		var zoom_factor =  start_distance / current_distance
		if can_zoom:
			position = start_zoom / zoom_factor

Could anyone enlighten me?
Thank you.

It would be easier to help you if you wrapped your code in a code block by pressing this button:
image

I believe you could flip the vector by just doing this:

var zoom_factor = -(start_distance / current_distance)

Notice the - sign.

1 Like

Ah I see, sorry for the wrapper, my first time posting (I fix the wrapper and add all the problematic functions ). I did try changing the code based on what you suggest, but then the camera suddenly jumped to somewhere else entirely. And yes, I put the - there. I converted a 2D touch mechanic into 3D. It seems I have butchered the script.
and thank you for the reply, I really appreciate it.