Camera rotation ease out

So, I’m basically new to Unity and have been messing with it for the past couple of days. I’m fairly familiar with coding, but am having a little bit of a hard time wrapping my head around how to handle vectors and easing.

I have an object that’s the only subject in my scene. I have an empty GameObject (called CameraTGT) that’s parented to my subject. I want to be able to rotate the camera around that CameraTGT object when I’m holding down the left mouse button, but when I let go, I want it to follow the direction the mouse was going, but to ease to a smooth stop.

I’m guessing that I would grab my camera’s position from the previous frame and my camera position from my current frame and make a vector out of it. If the MouseButton is down, then it doesn’t ease at all. If the MouseButton is up though, it should calculate the vector for the current frame, and then each subsequent frame should be multiplied by something like 90%, until it’s basically at a stop.

This sounds stupid, but I can’t understand how to translate the camera’s positions to a Vector that can then be applied repeatedly on future frames so that it slows to a stop…

PS - the object can’t rotate, only the camera…

Any suggestions?

Parent the camera to a dummy object at the target position, and rotate it around the target by rotating that dummy object. Then you only have one float (transform.rotation.eulerAngles.y) to worry about and no loss of precision.

To give the camera some rotational inertia:

  • While the LMB is pressed, store the
    difference between last frame
    and this frame (angular velocity).
  • While the LMB is released, add the
    stored rotational velocity to the
    current rotation, and reduce the
    stored vel by 10%.

That’s a crude solution. Ideally you’d calculate the rotational velocity properly using Time.deltaTime and decay it properly to ensure it behaves the same at all framerates.

@Winterblood Doesn’t work for me because I found situations where I moved the mouse quickly to the right, and without noticing it, introduced a tiny movement to the left at the last moment.
Stil investigating what works better.