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.