How can the following code be modified?
I dont understand. You want to zoom at mouse cursor position on the screen?
How do I make the camera zoom toward the mouse position for a character that uses a spring arm?
Is there a demo? ![]()
I am not sure but either you want
- Camera Zooming on Character/Pawn something like this
- A really really zoom/binocular/ads is something like this
- Since you are mentioning mouse position I feel it can be maybe a top down, RTS style camera is something like this or this
if you are looking RTS camera, things to consider.
- Locked, unlocked panning.
- Panning mechanics and inputs ( keyboard, screen edge panning, speed etc)
- Distance to object vs distance to ground
- Easing, angle of attack, rotation, bounds and limits
Which one you are trying to do?
I still cant picture what you want to achieve. Is it top down game? Third Person or 1st person? When do you want to use this zoom features and how you expect to use it? Give more details if you want us to help.
Hi there, that is fairly simple.
You can start with getting the mouse position in the world with deproject.
LetsSayThis MouseDeprojectLoc
In you character / component / camera where ever you are writing logic;
MousePos = LineTraceSingle ( MouseDeprojectLoc, MouseDeprojectLoc + MouseDeprojectDir * 10000) ->Hit() -> HitLocation Example Tutorial
This is basically true world location under your mouse.
TargetCameraLoc = MousePos
CurrentCameraLoc = SpringArm->WorldLocation;
You can use this to OnMouseWheel-> Set (ZoomFractionLocation)
ZoomFractionLocation = Lerp (CurrentCameraLoc ,TargetCameraLoc , FractionOfZoom)
FractionOfZoom is something like 0.2 since you don’t want to go full zoom on one click or one wheel step. Simply by this you setting a location between your current camera and the mouse world since we want a gradual zoom.
Then you can simply zoom in
OnTick -> SetSpringArmLocation(VInterpTo (CurrentCameraLoc , ZoomFractionLocation, DeltaTime, Speed(5) ))
Recap:
OnMousewheel - > Set (ZoomFractionLocation )
OnTick → MovesCamera with Vinterp over time to ZoomFractionLocation




