# Camera Movement Smoothing

Given a camera that is looking at an object…
This object can turn left or right, and when it does, i want to have a smoothed delay given when the camera reacts.

e.g.
When the object moves, the camera should slowly begin to follow then speed up. However, the camera should lag behind slightly. When the object stops moving, the camera should be able to catch up with it but must slow to a stop when it gets close enough. (Essentially the action that takes place with animation smoothing in some animation programs.)

How would i implement this?

I don’t know if I’m fully qualified to answer this because I myself often think about even better solutions for my current projects camera system.

So I’m going to assume that the camera should always have a certain relative position to your main character or object.

If that’s the case you can create an Empty Game Object and position it as a child of your main object and position it to where the camera should be when it comes to a rest. You will use this Empty Game Object as a Transform.position or Vector3 in your script that moves your camera.

So essentially you will use this Empty Game Object Position to determine where the camera should end up (you must update it every time the character/object moves). And then you use that position to move the Camera from it’s current location to the destination point using the best math you can come up with.

You will most likely want to keep the Camera’s view (LookAt()) locked onto the object. And you will track a start position (camera’s current position) and end position (Empty Game Object that’s child of main object).

You must also retrieve the time when the camera’s movement begins and the total distance to be traveled. Using these two transform points, the total distance to be traveled, and the time your movement started you can calculate the distance traveled which is a percentage (distance traveled/total Distance to be traveled) relative to the time elapsed.

Combining all of this with Vector3.lerp for the movement and Quaternion.slerp for the rotation you can achieve some pretty smooth and natural camera rotations and movements.

Hopefully that helps, I could post the actual code but I’m hoping if you get it working you can post yours if my ideas help you. Or maybe someone who really knows their stuff can come and give an even better answer.

I will be bookmarking this page to see if someone can come up with something better or specific code to compare with mine.

The advantage of this kind of system is that really any kind of control scheme should work the same since the whole system is based on the camera’s end position which is relative to the main object. And then it’s all about moving the camera as smoothly as possible with the Lerp and Slerps.