DEV Community

Cover image for How to Create a Smooth Camera Follow in Unity Using Cinemachine
Alok Krishali
Alok Krishali

Posted on

How to Create a Smooth Camera Follow in Unity Using Cinemachine

Have you ever played a game where the camera follows the player so smoothly that you barely notice it moving? A good camera system can make a big difference in how a game feels. On the other hand, a camera that moves too quickly, shakes unnecessarily, or struggles to keep up with the player can make even a good game feel uncomfortable.

If you are developing a game in Unity, you don't need to build a camera-follow system from scratch. Unity Cinemachine provides tools that help you create smooth, responsive, and professional-looking cameras with very little code.

In this tutorial, you will learn how to set up a camera that follows your player using Cinemachine, adjust its smoothness, and fix some common problems along the way.

Let's get started!

What Is Cinemachine in Unity?

Cinemachine is a camera system for Unity that helps developers create better camera movements without writing complex camera scripts.

Instead of manually updating the camera position every frame, you can configure Cinemachine to follow a target and control how the camera behaves.

With Cinemachine, you can:

  • Make the camera smoothly follow the player.
  • Control the camera's follow distance and offset.
  • Adjust how quickly the camera responds to player movement.
  • Create different camera behaviours for different gameplay situations.
  • Build camera systems for 2D and 3D games.

For this tutorial, we will create a basic third-person camera that follows a player in a 3D Unity scene.

Step 1: Create a Unity Project

First, open Unity Hub and create a new 3D project. You can use an existing project if you already have a player character and a scene.

For a quick test, follow these steps:

  1. Create a new 3D project.
  2. Add a Plane to the scene to act as the ground.
  3. Add a Capsule to represent the player.
  4. Position the Capsule slightly above the Plane.
  5. Add a simple movement script if you want to test the camera while moving the player.

Make sure your player object has a meaningful name, such as Player.

You can use a character model instead of a Capsule later. The Capsule is simply an easy way to test whether your camera is working correctly.

Note: Before adjusting camera settings, test the scene with a simple player object. This helps you identify camera problems without worrying about character animations, models, or complicated movement systems.

Step 2: Install Cinemachine

Now, let's install Cinemachine in your project.

  1. Open Unity.
  2. Go to Window > Package Management > Package Manager. Depending on your Unity version, you may find Package Manager under the Window menu directly.
  3. Select Unity Registry from the package source dropdown.
  4. Search for Cinemachine.
  5. Select the package and click Install.

Wait for Unity to finish installing the package.

The exact interface can vary depending on your Unity and Cinemachine versions. This tutorial uses the Cinemachine workflow available in modern Unity versions, particularly Cinemachine 3.

Important: Cinemachine 2 and Cinemachine 3 have some differences in component names and setup. If your Inspector shows different options, check which version is installed before following the remaining steps.

Step 3: Create a Cinemachine Camera

After installing Cinemachine, create a camera that will follow the player.

  1. Select your player object in the Hierarchy.
  2. Open the GameObject menu.
  3. Find the Cinemachine camera creation option. In Cinemachine 3, this is commonly available under Cinemachine > Cinemachine Camera.
  4. Create the Cinemachine Camera.

You can also create the camera first and assign the player afterward.

When the camera is created, Unity may configure a Cinemachine Brain on the Main Camera automatically. If it doesn't, select your Main Camera and add the Cinemachine Brain component from the Inspector.

The Main Camera renders the scene, while the Cinemachine Camera controls the desired camera behaviour through the Brain.

Note: Do not create multiple ordinary cameras unless your game needs them. For a basic follow camera, one Main Camera and one Cinemachine Camera are enough.

Step 4: Assign the Player as the Follow Target

This is the most important step.

Select your Cinemachine Camera in the Hierarchy. Look at its Inspector and find the target settings.

Depending on the Cinemachine version, you may see fields such as Tracking Target, Follow, or other target-related options.

Drag your Player object into the appropriate tracking or follow target field.

The camera now knows which object it should track.

However, simply assigning the target does not guarantee smooth movement. You still need to configure how the camera follows the player.

For a third-person camera, you generally want the camera to stay behind and slightly above the player rather than sitting directly inside the character.

Step 5: Adjust the Camera Position and Follow Distance

Now let's position the camera so the player is clearly visible.

In Cinemachine 3, select your Cinemachine Camera and look for the Position Control settings. For a basic third-person follow camera, you can use a Third Person Follow position control component or another suitable follow setup, depending on your project.

A common starting point is:

  • Camera distance: 5 units.
  • Camera height: 2 units.
  • Camera side offset: 0 units.
  • Vertical framing: Keep the player near the centre of the screen.

The exact values depend on your character's size and the type of game you are making.

If your Cinemachine Camera uses a Third Person Follow component, adjust its camera distance, vertical arm length, and camera side settings to get the desired view.

If you are creating a top-down game, a third-person camera setup may not be appropriate. Choose a camera configuration that matches your gameplay.

Note: Think about the player's surroundings, not just the character. The camera should show enough of the environment for players to see obstacles, enemies, and upcoming paths.

Step 6: Make the Camera Follow Smoothly

Now comes the part that makes the camera feel better.

Select your Cinemachine Camera and find the settings related to damping or follow smoothing.

Depending on your selected position control, these options may appear as damping values, a damping vector, or a similar setting.

Damping controls how gradually the camera responds when the target moves.

Try starting with moderate damping values, such as around 0.5 to 1.0 where the selected component exposes values in that range. These are only starting points, not universal settings.

Test your game and adjust the values based on the result.

What happens when damping changes?

  • Very low damping: The camera reacts quickly but may feel rigid or abrupt.
  • Moderate damping: The camera follows smoothly while remaining responsive.
  • Very high damping: The camera takes longer to catch up and may feel delayed.

For a fast-paced action game, lower damping may feel better. For a relaxed exploration game, a slower response may create a more cinematic experience.

Note: Smoothness does not always mean using the highest damping value. Your goal is to make the camera comfortable to control without making it feel disconnected from the player.

Step 7: Test the Camera with Player Movement

Now play the scene and move your player around.

Observe the camera while the player moves forward, backward, and sideways.

Ask yourself these questions:

  • Does the camera keep the player visible?
  • Does it move smoothly when the player changes direction?
  • Does it take too long to catch up?
  • Does the player remain framed correctly during movement?

If the camera feels too slow, reduce the damping. If it feels too rigid, increase the damping slightly.

Make small changes and test again. This is usually the easiest way to find the right settings.

If your player uses a movement script, make sure the script moves the same GameObject that you assigned as the Cinemachine tracking target.

Also, check that your player movement and camera setup work together. For example, if the character rotates independently from its movement direction, you may need to adjust the camera's rotation settings separately.

Step 8: Add Camera Rotation Controls (Optional)

A third-person camera often needs mouse or controller input so players can look around.

You can build this behaviour using Cinemachine's rotation controls, input integration, and the Unity Input System.

The exact setup depends on your Cinemachine version and input configuration. You may need to configure a rotation controller, input axes, or a suitable Cinemachine input component.

For mouse controls, consider sensitivity and vertical rotation limits. For controller input, consider dead zones and separate horizontal and vertical sensitivity.

If you only need a camera that follows the player without rotating, you can skip this step.

Note: Avoid making the camera rotate too quickly. Sudden rotation can make it difficult for players to judge distances and can create an uncomfortable experience.

Step 9: Fix Common Cinemachine Camera Problems

Sometimes the camera does not behave as expected. Here are a few things to check.

Problem 1: The camera does not follow the player

Check that the player is assigned to the correct target field. Also, make sure the Main Camera has a Cinemachine Brain and that the Cinemachine Camera is active.

Problem 2: The camera movement feels jerky

Check whether your player movement is smooth and whether multiple scripts are trying to control the camera. Avoid manually changing the Main Camera's transform while Cinemachine is controlling it.

Also, check your update settings if your player moves through physics. Inconsistent movement timing can contribute to visible jitter.

Problem 3: The camera follows too slowly

Reduce the damping values. If the camera is using a third-person follow component, check the available damping settings rather than changing unrelated camera properties.

Problem 4: The player disappears behind objects

Use an appropriate camera collision solution for your Cinemachine setup. A camera collision extension or suitable collision component can help prevent the camera from passing through walls, depending on your installed version and configuration.

Problem 5: The camera shows the wrong view

Check the Cinemachine Camera's position and rotation controls, target assignment, and priority. If you have multiple Cinemachine Cameras, make sure the intended camera is active and has the appropriate priority.

Best Practices for a Smooth Camera Follow

Before finishing your camera setup, keep these tips in mind:

  • Start with a simple camera setup and add features only when needed.
  • Choose damping values based on the speed and style of your game.
  • Test camera movement at different player speeds.
  • Keep the player visible during jumps and direction changes.
  • Use camera collision handling in environments with walls and obstacles.
  • Test on the target platform, especially if you are developing for mobile devices.
  • Avoid adding unnecessary camera effects that distract from gameplay.

Remember, the best camera is one that supports the gameplay without drawing too much attention to itself.

Conclusion

Creating a smooth camera follow system in Unity becomes much easier with Cinemachine. You can install the package, create a Cinemachine Camera, assign your player as the target, configure the camera position, and adjust damping to get the movement you want.

You don't need a complicated camera script to achieve a good result. Start with the basic setup, test it in your scene, and adjust the settings until the camera feels natural.

Once you understand these fundamentals, you can explore more advanced features such as camera collision, mouse look, camera blending, and different camera behaviours for different gameplay situations.

Did this tutorial help you create a smoother camera in Unity? Share your experience in the comments, and let us know which Cinemachine feature you would like to learn next. If you found this guide useful, don't forget to share it with other Unity developers!

Frequently Asked Questions (FAQs)

1. Is Cinemachine free to use in Unity?

Yes. Cinemachine is available as a Unity package and can be installed through the Package Manager. Check the package information for your Unity version to confirm compatibility.

2. Do I need to write C# code to make a camera follow the player?

No. You can create a basic camera-follow system using Cinemachine's Inspector settings. C# code may be useful when you need custom behaviour or want to control the camera dynamically.

3. What is damping in Cinemachine?

Damping controls how gradually the camera responds to changes in its target's position or rotation. Higher damping generally produces a slower response, while lower damping makes the camera react more quickly.

4. Can I use Cinemachine for a 2D game?

Yes. Cinemachine supports 2D camera setups. You can configure the camera to follow a 2D player and adjust framing and damping to create smooth movement across your level.

5. Why does my Cinemachine camera shake when the player moves?

Camera shake or jitter can occur for several reasons, including inconsistent player movement, physics update timing, multiple scripts controlling the camera, or unsuitable damping settings. Check your movement and camera configuration first, then adjust the relevant settings to identify the cause.

Thanks for reading!

If you found this article useful:

👍 Give it a like to show your support.
🔄 Share it with other Unity developers who might find it helpful.
💬 Leave a comment if you have faced a different coroutine problem or have another solution to share.
🚀 Follow us for more practical Unity tutorials, C# tips, and game development guides.
Have a great time building and debugging your games!

Happy Game Development! 🎮

Top comments (0)