Zooming to a specific point on an object


I wasn’t sure in which section of the forums should I post this question, so I hope I chose it correctly.

Say I have an object in the scene and a camera with a spring arm the looks on the object. You can rotate around the object and zoom. Simple enough. But what if I want to zoom to a place under the mouse cursor. I know about Get Hit Result Under Cursor for Objects and Find look at rotation, but the thing is that the place that I zoom in on should remain under cursor even after the zoom operation takes place. Is there a tool for that in Unreal or do I need to employ some mathematics to find out?



I´m not sure whether I understand you correctly but am I right that the issue you´re having is that when you zoom in, the object you had your mouse on shifts to the middle of the screen? Because you´re zooming onto it? If not how does your desired zoom differs from what you have right now?

If the object is actually moving away from the mouse: How do you perform your zoom? Could you post the code/blueprint here?
Intuitively I would say right now that it should work if you move the camera towards the location under your mouse without rotating the camera at all.
This way the object should stay at it´s relative position on your screen and just grow in size while you get closer but not move away.

You could archieve this by linetracing under your mouse or getting the hit result as you said and then taking than location and subtracting your camera position from it.
That will give you a vector pointing straight from the camera to the location.
You could then interpolate the camera position along that line by adding fractions of that vector to your camera position while you zoom which should hopefully zoom you onto the object the way you wish.

Yes, because currently I just update the arm length (or FOV) without targeting the point under the cursor. I am asking how to achieve the effect…

The idea with shifting the camera instead of rotating it looks promising. Obviously, I got too much carried away with the rotation idea. I’ll give it a shot and let you know.


Changing the target offset of the spring seems to do the trick. So thanks for the idea.

However, when I start rotating again, now the actual center of the rotation is way off… At this point I am resetting it back to (0,0,0) which again zooms out. If I were to recreate a similar zoom factor, I would need to rotate the spring arm to the position of the camera before resetting the target offset. Any idea how to do that? It should be simple, yet I cannot find the right tools for that.

I have the current rotation of the spring arm and I have the vector that shifts the camera (target offset). Now all I need to do is to shift the rotation by that vector. Which should get me a new rotation that would again target (0,0,0), but this time from the current camera position… And then of course to update the spring arm length, but that’s simple.

OK, in the end I solved it like this:

As foodi suggested, I update the target offset in the direction of the point that is under the cursor.

When I then start rotating the camera I interpolate 3 things:

  • target offset back to (0,0,0)
  • spring arm length so that the new size is equal to the length of the vector pointing from the camera position to the spring arm position (i.e. the center of the rotation)
  • angle of the spring arm in such a way that the direction is the same as it was when the camera was shifted by the target offset

When the interpolation speed is not too high it makes a nice transition effect.

Follow your solution, my camera location will change to the mouse location, but it will always on the center. why?