# How is this camera settling done?

For clarification: I don't need to know how to rotate the camera. What I'm asking instead is how the movement of the camera AFTER the mouse move is calculated (the "slow fade out"). I've tried a lot, but it never looks right to me.

The question:

I have uploaded a video here.

This video shows a camera settling behaviour.

In this video, the mouse pointer is moved swiftly from left to right.

The camera however does not abruptly start moving to the other direction, instead it settles in the previous direction before going to the other direction.

I would like to know how this is settling is done. I have tried really much to recreate this behaviour:

Taking into account the overall speed until the next zero mouse movement, fading out the last non-zero mouse movement, just anything that I could think of.

Could anybody tell how he thinks this could be done?

• Look into Cinemachine, its a package from Unity that has the ability to achieve the behavior you are interested in. – Gary Holiday Feb 11 at 16:27
• You might want to add what you have tried and why it did not work, this would help give answers that are more adequate to your situation. – Alexandre Vaillancourt Feb 11 at 17:22
• Possible duplicate of How is this rotation done? – Gary Holiday Feb 11 at 20:03
• @GaryHoliday No, this question here is more specific. – tmighty Feb 11 at 23:11

## 1 Answer

Have you tried Vector3.Lerp? i.e. Lerping your current position to the target position calculated by the mouse movement.

Lerp is short for linear interpolation. In this case you'd move part way to the target. The final parameter is what portion of the total distance you want to move (in this case 50%). Lowering this would get a slower camera feel. There's also Vector2.Lerp, if you're doing a 2D game.

Position = Vector3.Lerp(Position, TargetPosition, 0.5F);


https://en.wikipedia.org/wiki/Linear_interpolation

Note: I don't use Unity

• Yes, I've tried that. What I don't understand (if I look at the video) is how it's calculated that the camera still swings to the right while some more and becomes slower while the mouse pointer is already moving the left. – tmighty Feb 11 at 21:12
• Try changing the acceleration of the camera instead of the position? That would make sense if you want the camera to keep going. – gusg21 Feb 11 at 21:49
• I'm setting the position of the camera directly using the mouse position. The camera itself doesn't have an acceleration. Or perhaps I don't understand what you mean. – tmighty Feb 11 at 23:13
• I will improve my question to make the problem better to be understood. – tmighty Feb 11 at 23:14
• I don't use Unity, so I can't really help you any more, sorry. – gusg21 Feb 11 at 23:42