Perfect Pinch Zoom?

Hi All!

I am searching for a solution to how to make a perfect pinch zoom by moving the camera along the forward:

Set up:

Horizontal plane centred at the origin with all Game objects.

Perspective camera with FOV 10, offset at (10,10,10) looking down at a 45 degrees angle, so that it looks at the origin (there is also a rotation of 45 degrees around the axis pointing up, to achieve this).

What I need:

When I place two fingers on the screen I am touching two GameObjects with them - so the screen coordinates under the fingers correspond to certain world coordinates. When I make a pinch movement (with moving two fingers or only one) I want the new screen coordinates to correspond to the same world coordinates that were under the fingers at the beginning of the whole interaction.

So to simplify even further - whenever I touch the screen with two fingers, I want the world coordinates corresponding to the screen coordinates under my fingers to always stay under the fingers (allowing a very small margin of error).

An example of this perfect zoom for which I am looking for you can see in the mobile game Boom Beach from Supercell.

I already tried to move the camera along its forward vector and to reposition it and I get pretty good results, but pretty much always the GameObjects underneath ‘slip’ away from under my fingers, that is at some points are no longer underneath them. It would be great if there was a mathematical solution to this, but if it’s necessary to compute the answer (through some search for example) then this is totally fine.

If the setup/scenario is not clear, I could provide some sketches to clarify it a bit more.

Hope someone can help me! :slight_smile:

I dont understand if you have problems positioning the camera knowing exactly where the 2 points are. Or if you have troubles finding the 2 points.
Can you just position 2 boxes in the exact points?