I am making 2d game so I use mode 2d ascpect expand, and with those settings following code does not work with multiple window resolutions, but works perfect on default window resolution.
I tried adapting viewport to OS.getrealwindow_size() or something, but it did not work.
var viewport = get_viewport()
var direction = viewport.get_mouse_position() - viewport.size / 2.0
var percent = (direction / viewport.size * 2).length()
var camera_position = Vector2()
var max_zoom_distance = get_current_weapon().raycast.cast_to.x
if percent < ZOOM_MAX_CAMERA_PERCENT:
camera_position = global_position + direction.normalized() * max_zoom_distance * (percent / ZOOM_MAX_CAMERA_PERCENT)
camera_position = global_position + direction.normalized() * max_zoom_distance
camera.global_position = lerp(camera.global_position, camera_position, Game.zoom_sensitivity)
Found the formula originally from https://godotengine.org/qa/95641/move-camera-to-mouse ...
Goal is to move camera towards mouse and I call it "zoom" because its for shooter game.