# Hiding System

{% hint style="info" %}
The **Hiding System** allows you to hide to any location by simply animating the Virtual Camera. When you are being chased by an enemy, you can hide, but don't get spotted where you are hiding.
{% endhint %}

### Adding Hiding Places

1. Add a **Virtual Camera** by selecting **Game Object -> Cinemachine -> Virtual Camera** to the object that represents the hiding place.
2. In the **Virtual Camera** component settings, set **Body** and **Aim** to **Do nothing**.
3. Move the camera to the potential hide starting position, where the player camera will move when you interact with the hiding place.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2F8PYM86OAQ7ViHemth8kG%2FScreenshot_3.png?alt=media&#x26;token=ef73ec85-e42c-4cfd-b415-6cc28ba3072c" alt=""><figcaption></figcaption></figure>

4. Animate the **Virtual Camera** and create two animations. One will be a **Hide** animation and the other **Unhide** animation.
5. Modify the Animator so that you will be able to hide from any state and unhide by transitioning from hide state.

{% hint style="warning" %}
Make sure that the **transition duration** between the **Hide** and **Unhide** states is zero.
{% endhint %}

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FoNDMQasFuarO4VuxEeZi%2FScreenshot_4.png?alt=media&#x26;token=ed3de866-9a2f-42d8-ad1d-7d1b4cded6ca" alt=""><figcaption></figcaption></figure>

6. Create a new bool parameter and name it **IsHiding**. Set it so that the transition to the **Hide** state only occurs when **IsHiding** is true, and to the **Unhide** state when **IsHiding** is false.
7. Add a **Hiding Interact** component to the object you want to interact with when you want to hide.

{% hint style="info" %}
You can define whether you want to use the **Interact** or **Trigger** hiding style. If you set the **Hiding Style** to **Interact**, you will hide when you press E on the interactable object. If you set it to **Trigger**, you will hide when you move through a **Collider** that is marked as **Is Trigger** with this component added to it.
{% endhint %}

8. Define the hiding and unhiding position of the player. The **Hiding Position** represents the location where the player object will be teleported after hiding. The **Unhide Position** represents where the player will be teleported to after unhiding.

{% hint style="danger" %}
Both the **Hide** and **Unhide** positions must be placed where the player foot will be. The Unhide position can be debugged by enabling the **Draw Gizmos** option. The red dot represents where the player camera is located. After unhide, the Main Camera will move to the player controller camera position.
{% endhint %}

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FKLp2BCYFsJ9A7Efpk33m%2FScreenshot_5.png?alt=media&#x26;token=206ec463-6c94-4fca-a953-fdabda1e5f9c" alt=""><figcaption></figcaption></figure>

9. Assign references to the **Virtual Camera** and **Animator** and adjust the **Blend Settings**.
10. Adjust the **Animation Settings** using the corresponding **Animator State** and **Parameter** names.

{% hint style="info" %}
You can see how the **Hiding System** works and how it is set up in the **Elevator** scene and on the bottom floor.
{% endhint %}
