I was searching for a simple and straightforward way to get a simple smooth zooming by setting SpringArm lenght using mouse wheel. By default, if you hook it up, the movement is very coarse due to the mouse wheel stepping. I went through quite a few threads but I’ve only found either overcomplicated setups or actual plugins, not a simple blueprint solution. After a while of experimenting, I’ve came up with something simple that works, so I’d like to share it because I am sure someone else will be looking for this in the future
1, InputAxis Zoom event is mapped to mouse wheel axis in input panel of project settings
2, Axis value is multiplied by -1000 to make zooming sensitive enough in the scene of my scale. This will depend on the scale of your scene. You can make it a positive number to invert the mouse wheel zooming direction.
3, Cam Zoom Destination is a variable where I’m storing the destination length of the SpringArm I want to be smoothly interpolating to from the current spring arm length
4, Clamp clamps the range of the Cam Zoom Destination so that the player can’t zoom to far in or out.
5, Interp Speed parameter in the FInterp To node is the actual speed of the transition smoothness. The lower the number, the smoother will the zooming be.
6, Rest is self explanatory, it’s just about hooking it up like on the picture.
Does anyone know how to implement this in C++? I’ve managed to reproduce your BP fine, and it works very nicely. However, when I try to recreate this in C++ it doesn’t seem to make it smooth (though it does seem to be interpolating). I’m no expert at either BP or C++ however, and trying to find any resources specifically focused on creating a smooth top-down camera zoom in C++ is challenging to say the least. I would be very grateful for any direction.
There’s no reason it should not work in C++ exactly the same. But why would you want to C++ this anyway? I mean it’s not like performance impact will be noticeable at all. But yeah, if it doesn’t work, then just give it a bit more time debugging and you will certainly find some trivial mistake, because this is really simple. The most common mistake in this type of thing is having source value (Current) also present somewhere in what’s being fed into the Target value in the InterpTo function.
CamZoomDestination needs to be passed in as a reference argument. It should ideally be member variable of your class or component, so the value is held during the lifetime of it. If it was declared inside the scope of the function, then it’d be die at the end of each call and would be re-declared each frame, assuming you run in on tick or input poll event. Also those -1000 and 10 magic numbers need to be adjusted for your scene size, as I already mentioned.
And Min and Max zoom distances would probably be better placed outside of the function, so they are not unnecessarily redeclared every time. Or if you are fine with it, you can just omit those number and mash them right into the clamp function, but that’s even more magic numbers
I am trying to implement your blueprint snippet with little success. All I am able to accomplish is setting the default SpringArm length, which is bound to the “min” value in the clamp. In other words, by default i am zoomed in and I cannot zoom out.
If you can help, I have some additional questions as well. One, does this need to be hooked up to the “Event Tick” with a gate or something? Also, is there a way to set the default Spring Arm Length that is not the min or max clamp value?
So, I figured it out. Thanks for this code first of all. Very Nice.
The ‘Zoom Camera’ on my input commands was set to ‘Scroll Wheel +’ and ‘Scroll Wheel -’ where i just needed to assign ‘Scroll Axis’. Other inputs worked, for example, when I used period and comma to increase and decrease the Zoom.