# Camera Follower

{% hint style="success" %}
Suitable for simple camera behaviours:\
\- Follows targets position (also rotation) **without** *obstacles avoid*\
\- Has Shake effect module\
\- Has FOV/Orthographic handler module\
\- Point of view (POV) states and switch between them smoothly. Editor POV create and preview logic in inspector.
{% endhint %}

## How it works

You can find prefab in **\_Main\Prefabs\Common\CameraCustom\CameraHolder.prefab**

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2FaLHHy5tmPlkceQ8zb4hb%2Fimage.png?alt=media&#x26;token=8840816c-db4e-4719-9c77-73fc3e5f7165" alt=""><figcaption><p>Structure in prefab</p></figcaption></figure>

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2F87xDGog7UgccgYtvp2K7%2Fimage.png?alt=media&#x26;token=09c12750-21ec-4cb9-84f8-564750d8ec16" alt=""><figcaption><p>How it's structures runtime (you can unparent MainCamera in scene)</p></figcaption></figure>

"CameraHolder" object is holder of Camera custom system. "Camera \[parent]" object is additional layer for Object shake. CameraHolder moves camera parent in POV change operations and it's posible to do shake while POV changing. Holder has MainCamera object reference (camera itself with Cinemachine brain on it) and Main Virtual Camera is Cinemachine virtual camera.

{% hint style="success" %}
You can add more Virtual cameras in scene and with custom logic and switch between them with Virtual camera priority property.\
\
We often use CameraHolder as default camera follower for player and add few virtual cameras to make cutscenes with it and transitions.
{% endhint %}

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2FwaBgErgQZranqO2Rc53e%2Fimage.png?alt=media&#x26;token=a77171ed-e638-4b5f-96eb-a25bf230e13e" alt=""><figcaption><p>Inspector variables</p></figcaption></figure>

* Follow Target -> what should CameraHolder follow
* Copy Follow Target Rotation -> should CameraHolder follow target object rotation too?
* Follow Position Lerp -> how fast will CameraHolder  follow to target object position\
  less value -> more time needs to reach target completely
* Follow Rotation Lerp -> the same as Follow Position Lerp but for rotation\ <mark style="color:orange;">**(has no effect if Copy Follow Target Rotation set to false)**</mark>
* Change POV Pos/Rot curves controlles how POV MainCamera local Pos/Rot with change from one to another (interpolates from 0 to 1)
* <mark style="color:blue;">**Camera POV\_s**</mark> -> core component to switch "Camera \[parent]" object local Pos+Rot by POV *(point of view)* name or array index. MainCamera replaced under Camera \[parent]  so we can freely change Camera \[parent] local Pos+Rot and **Camera POV\_s** is array of point of views (states).
* Change Target Position/Rotation curves -> controlles how Camera (holder) Pos/Rot with change from current Camera (holder) point to new Follow Target point (interpolates from 0 to 1).

{% hint style="warning" %}
You should keep "Main camera" object local position and rotation as (0, 0, 0) and change Camera \[parent] instead.
{% endhint %}

***EDITOR TOOLS***

* <mark style="color:red;">**POV index**</mark> -> current selected editor <mark style="color:blue;">**Camera POV\_s**</mark> index to perform operations:\
  \- Preview POV (toggle it on and "Camera \[parent]" transform will set to POV index from Camera POV\_s array)\
  \- **Refresh POV index (button)** -> refreshes POV from Camera POV\_s array by POV index. Values will be taken from "Camera \[parent]" current transform values.
* **Add POV to end (button)** -> creates POV by taking current "Camera \[parent]" transform values and adds it to the end of <mark style="color:blue;">**Camera POV\_s**</mark>

## Connected modules

Camera Custom uses [**Object Shake**](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/ready-to-use-scipts/objectshake) and **CameraFOVHandler**.\
They can be accessed by CameraFollower instance -> ShakeEffect and CameraFOVHandler properties.\
more **API** -> see script CameraFollower.

Example of Camera Custom can be found here:\
\&#xNAN;**\_Examples\Camera Custom\Example.scene**
