This was for a touch screen project, so you might need to tinker with it a little to behave better with a mouse.
Add this script to a camera. Add some game object to the target variable in the inspector, and in play moode just click-drag the mouse.
Drag it faster and it will do that “slow-mo” effect when the orbit continues for a bit and slows down to a stop.
Oh, and it’s one of the first things I ever wrote in Unity, a long time ago, so don’t judge the code
Adding the zoom is pretty easy.
Should be something like this:
Just figure out what are your zoom limits and sensitivity value after you assign this either to the FOV of the camera or the distance parameter in the script I attached.
Thanks cyb3rmaniak!
It worked great after a bit of tweaking.
I couldn’t get the targetting to work, but I just moved my object to the point the camera was pivoting on and it worked fine.
Haven’t tried the zooming script yet. Will try that soon.
What is the parameter to change in order to make the object continuing to move a lot more after having dragged it? (in other words: to make the “slow motion” last longer) Is it possible to do that?
It’s totally possible.
I admit it’s not writen clearly as I would like it to be.
It’s not an exposed parameter, but pretty easy to tweak.
The calculations about continuing the rotation takes into account the last drag the user did - the rotation that the camera received and the time between when the user clicked and let go of the mouse button.
Inside ContinueRotation(), which handles the continued movement, there’s a parameter called TimeDiff. It’s clamped from 0 to 1, since when using a touch screen the drags were much faster than when using the mouse. so you might want to change that to clamp between 0 and 2 or 0 and 3. If you’re at it, put it in a parameter, let’s say fClampedMax:
var TimeDiff = Mathf.Clamp((afterRotation.z - beforeRotation.z) * 2,0,fClampedMax);
var fRotationSmoothing = Mathf.InverseLerp(0,fClampedMax,TimeDiff);
Didn’t have time to test it out in Unity, but hopefully it will help.
Also, try playing with “steps”. The bigger it is, the longer it will move.
If you still have problems let me know. Maybe I’ll re-write this to be a bit more efficient and easilly tweakable when I’ll have some time on my hands.
Thanks cyb3rmaniak, but i still have the same effect. I tried a lot with no results.
I also tried changing the steps value, then the cube moves for a longer time, but still with very tiny movements.
It works wonderfully. Only problem, the rotation snaps back to the previous position everytime I use the left mouse button. When I use left- and middle mouse button at the same time, this somehow doesn’t happen. Any ideas on how to change this in the script?