Zoom in and out to target with camera using touch controls

Try and open your phone’s gallery app and zoom in one of the pictures. Notice that the camera doesn’t zoom in the center but rather it zooms into the point in between your fingers. I’ve been trying to implement that in unreal engine in order to achieve a smooth and professional zoom-in-out function for my mobile base building game, but the task has been far more complicated than originally anticipated.

The surface logic is simple:
Zooming into a targeted point in world means that that point is the only one which maintains the same screen position after zooming. essentially, the only point that doesn’t move when zooming.

I am using an orthodox camera.

I tried to achieve that by simply adding to the camera’s world location the difference in the world location of the center of the 2 touch points of the fingers between before and after the zoom. That didn’t work though; it resulted in constant jittering of the camera, as it appears the difference was constantly being negated. I frankly have no idea as to why that happened and as far as I understand at present it appears that, simply because the check is repeating every tick (so long as there is pitch input), sometimes the world location just isn’t updated properly or something along these lines.

I tried dozens of methods in the past few days and none worked as expected, so if you have an algorithm or really any info which I might find useful please share as I am becoming increasingly desperate by the second

this problem was solved by using the solution I described above, but converting the screen position to world space by myself and not using the “convert screen position to world space” as it misfunctions for some reason. here’s a screenshot of the math for that conversion, if you use an orthographic camera like I do:

1 Like

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