[Unity] How to Make the Camera Follow the Character — Including Rotation Based on Character Direction

In Unity, there are various ways to make the camera follow a player or object. You can choose the most suitable method depending on your needs — from simple coding techniques to advanced tools like Cinemachine.

This article provides a detailed guide on how to create a basic follow camera, as well as advanced camera control using Cinemachine.

  1. How to Set the Camera as a Child Object of the Follow Target
  2. How to Control the Camera Position via Script
  3. How to Use Cinemachine

Let’s go through them one by one!

Follow Methods

1. Set the Camera as a Child Object of the Player

The most basic way to implement camera follow is to update the camera’s position to match the target object’s position. This method keeps the camera at a fixed relative position to the target as it follows.

By making the camera a child of the player object, the camera will automatically follow as the child moves along with the player.

When you move the Cube, the camera follows it.

However, this simple method also has some drawbacks — the camera is affected by the target’s rotation.

For example, when a ball rolls, the camera will rotate along with it, which may not be desirable.

Another drawback is that since the follow happens in real-time, if the object moves abruptly, the camera can shift suddenly as well, which may feel jarring to the player. In such cases, it’s important to smooth out the camera’s movement.

How to Control the Camera Position and Fix Rotation via Script

To fix the rotation, controlling the camera’s position through a script is an effective method.

Additionally, you can make the camera’s movement smooth.

Attach the following script to the camera.

using UnityEngine;

public class CameraController : MonoBehaviour
{
    public Transform player;  // Player's Transform
    public Vector3 offset;    // Offset position between player and camera
    public float smoothTime = 0.3f;  // Parameter to adjust how smoothly the camera follows the player

    private Vector3 velocity = Vector3.zero;  // Velocity vector used by SmoothDamp for camera movement

    // Use LateUpdate to move the camera after the player has moved
    void LateUpdate()
    {
        // Make the camera follow the player's position
        Vector3 targetPosition = player.position + offset;
        targetPosition.z = transform.position.z;  // Keep the camera's original Z position fixed
        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
}

Please assign the player’s Transform and set the offset (relative position between player and camera) in the Inspector.

For the offset, specify the relative position between the player and the camera as a vector.

If you want the camera to capture the player from a diagonal or angled view, set the camera’s rotation in advance using the Inspector.

The smoothTime parameter adjusts how smoothly the camera follows the player.
A larger value makes the camera follow more slowly and smoothly, while a smaller value makes it follow more quickly.

Use LateUpdate for Camera Control

It’s recommended to update the camera’s position after all physical movements have been processed. Specifically, by updating the camera’s position in LateUpdate() instead of Update(), the camera follows the character smoothly because it adjusts after the character’s movement is fully applied.

3. Using Cinemachine

Another way to fix the rotation is by using Cinemachine.

Cinemachine is an official Unity package that allows you to control cameras easily without writing code.

Importing Cinemachine

To use it, open Window > Package Manager and import it from the Unity Registry.

Creating a Virtual Camera

Create a Virtual Camera from the Hierarchy window.

From the Inspector of the created Virtual Camera, drag and drop the target object into both the Follow and Look At fields.

Position and Rotation Settings

You can set the relative distance between the camera and the target using the following Offset settings.

The Body section controls the position, and the Aim section controls the rotation.

Result

The camera followed smoothly!

Conclusion

This was an overview of methods to make the camera follow objects in Unity. Approaches range from basic follow techniques to smooth interpolation and advanced camera control using Cinemachine. Because camera movement directly affects gameplay quality, it’s important to choose and adjust the best method for your specific situation.

Our recommendation is to use Cinemachine. It allows flexible camera follow setups without writing any code.

For advanced camera control in 2D games, this asset is highly recommended:

Pro Camera 2D – The definitive 2D & 2.5D camera plugin for Unity