Smooth Zoom to a Specific Point While Maintaining Camera Target Close to Center

Hi everyone,

I’m trying to implement a camera zoom that focuses on a specific point in the scene, while keeping the camera’s target as close to the center of the viewport as possible. The behavior I’m aiming for is somewhat similar to zoomToMouseLocation, but the point I’m zooming to is static.

My current approach is to compute the change in camera radius and add a fraction of the direction vector from the target to the static point. However, I’m encountering issues where the zooming behavior becomes glitchy, particularly with inconsistent zoom speed.

You can see my current attempt in this Playground: Babylon Playground.

The point I’m zooming to is in the top-left corner, but the zoom speed is uneven and it causes some glitches. Any insights or suggestions on how to improve this?

Thanks in advance!

Hello :slight_smile:

I’m not 100% sure I understood what you try to achieve, but if I understand well, you want to move camera target on one side while zooming in, and move it back to center while zooming out, right ?

Something like this ?

(The math is a bit dirty because single lined, but if it’s what you are looking for, I can detail :stuck_out_tongue: )

3 Likes

Hi @Tricotou,
In my case the initial target position and radius depend on model size which might vary drastically, so Math.atan(camera.radius - (initialRadius / 2.0)) might be too aggressive in some cases. But it gives me an idea of how to proceed. The oneliner is quite clear after reverse engineering it (-;
Thank you very much. Marking it as a solution :smile:

1 Like