Hi,
I’m looking for a blueprint setup for my zoom in/out camera.
How to make the camera target the cursor while zooming ?
I’ve tried with Get Mouse Position, but it’s only 2D coords. I’ve tried a ConvertMouseLocationToWorldSpace too, but my camera looks an object with a certain angle from the ground (20°), so there is a mismatch in one axis : each time I zoom, the camera moves on its Y axis (it probably don’t takes count of the difference between the Y coord of the camera and the distance between the camera and the targeted object).
I’m actually working with a camera attached to a spring arm (which length is modified to ajust the zoom), in a pawn class blueprint.
I’ve tried different ways, the best consists in converting the X/Y move of the cursor in the screen into %, and using this rate to scale the world location vector of the camera. But I’ve jumps from one position to another, as lerp doesn’t work correctly ; without explanation, even if the “set world location” node is linked to On Tick event, it only works during the time the wheel scroll “button” is activated (that is to say a fraction of second).
As you can see in the GIF, when I move the cursor over the cube, the camera zooms. I’m just checking that’s what you were looking for, before posting huge amounts of code. But it sounds like you want top down…
( I’m not moving closer to the cube, just mousing over )
Your gif is not very clear, but it seems to work. In my original post, I was working on a top-down view, the cursor was not the center of the screen, and it didn’t turn the camera around. Hard to me to explain a 3-years-old abandonned project though… @Aros_Prince, any precise request ?
OK, but the cursor is always the center of the screen, right? In such a case it is really easy. But in my case, moving the cursor around does not affect the camera in any way. Messing around with the mouse wheel does. And I need to keep the cursor where it is. As stated above, the solution described under the link is fine in my case. But thanks anyway.
The trick is to get the point under the cursor by calling GetHitResultUnderCursorForObjects which will get you the impact point. You can than subtract the the camera’s world location from the impact point which will get you a direction in which you need to shift the camera (without rotating it). You can do that for example by multiplying the vector by say 0.1 and adding it to the camera world location. If you have the camera attached to a spring arm, you can simply update the target offset property.
In case you need to also rotate the camera around a specific point, you need to employ some mechanism to reset the camera orientation. I use a timeline to interpolate the camera parameters when I need to reset it or start rotating the camera (see the link).