# Basic Setup with Cinemachine

This guide will show you one way you can set-up your player camera for multiplayer when you are using the Cinemachine package.

{% stepper %}
{% step %}

#### **Installing Cinemachine**

The first step — if you haven't done so already — is to install [Cinemachine](https://unity.com/features/cinemachine) through the [Unity Package Manager](https://learn.unity.com/tutorial/the-package-manager).

<figure><img src="/files/tjccgjUsQj6RKzWEaELW" alt=""><figcaption><p>Cinemachine installing</p></figcaption></figure>
{% endstep %}

{% step %}

#### **Adding the Cinemachine Brain**

Now that we have **Cinemachine** installed we can set it up. Add the **Cinemachine Brain** component to the **Main Camera** game object in the scene.

<figure><img src="/files/i9IMgpmllgmG0a5RA9Au" alt=""><figcaption><p><strong>Cinemachine Brain</strong> added to <strong>Main Camera</strong></p></figcaption></figure>
{% endstep %}

{% step %}

#### **Giving the player a camera holder**

Now create an empty Game Object on your **Player Prefab** and position it where you'd like. This will be our container for the **Cinemachine** **Camera**.

<figure><img src="/files/o1JVcR8X3djApdDvQz1y" alt=""><figcaption><p>Camera Holder created on the Player Prefab</p></figcaption></figure>
{% endstep %}

{% step %}

#### **Adding the Cinemachine Camera**

Now simply add the **Cinemachine Camera** component to the newly created **CameraHolder** game object.

<figure><img src="/files/KbO8acrI4Dn2tKNtqKs4" alt=""><figcaption><p>The <strong>Cinemachine Camera</strong> added to the <strong>Camera Holder</strong></p></figcaption></figure>
{% endstep %}

{% step %}

#### **Writing a PlayerCamera script**

Let's now add the following `PlayerCamera` script to the **Player Prefab** that we will use to take control of our **Camera** once our player spawns in.

{% code title="PlayerCamera.cs" lineNumbers="true" %}

```csharp
using FishNet.Object;
using Unity.Cinemachine;
using UnityEngine;

// This script will be a NetworkBehaviour so that we can use the OnStartClient override.
public class PlayerCamera : NetworkBehaviour
{
    [SerializeField] private CinemachineCamera _cinemachineCamera;

    // This method is called on the client after the object is spawned in.
    public override void OnStartClient()
    {
        // Simply enable our local cinemachine camera on the object if we are the owner.
        _cinemachineCamera.enabled = IsOwner;
    }
}
```

{% endcode %}

This script uses the [OnStartClient](/docs/guides/features/networked-gameobjects-and-scripts/network-behaviour-guides.md#onstartclient) override method from [NetworkBehaviour](/docs/guides/features/networked-gameobjects-and-scripts/network-behaviour-guides.md) to enable or disable the **Cinemachine Camera** component on the player objects depending on if they are our local player or not.
{% endstep %}

{% step %}

#### **Assign your references to the script**

Now select the **Player Camera** component in your **Player Prefab** and add drag the **Camera Holder** game object into the *Cinemachine Camera* field to assign it the component.

<figure><img src="/files/ssjGQI6hACNgvF21ncTE" alt=""><figcaption><p>The <strong>Player</strong> prefab with the <strong>Cinemachine Camera</strong> field filled in</p></figcaption></figure>
{% endstep %}

{% step %}

#### **Test the camera in-game**

With all that set you should be able to run the game and see how the camera from the scene is controlled by only your local player.

<figure><img src="/files/rODe2Murw33su8svr92L" alt=""><figcaption><p>Demonstration of the local camera</p></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Download the project files with these completed steps here, or explore the repository:

<a href="https://github.com/maxkratt/fish-networking-getting-started/releases/download/basic-setup-with-cinemachine/basic-setup-with-cinemachine.unitypackage" class="button primary" data-icon="down-to-line">Source Files</a> <a href="https://github.com/maxkratt/fish-networking-getting-started/tree/cinemachine-camera" class="button secondary" data-icon="github">Repository</a>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fish-networking.gitbook.io/docs/tutorials/getting-started/setting-up-a-camera/basic-setup-with-cinemachine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
