# Setting up the Cover Component

{% hint style="info" %}
**Note:** Emerald AI 2024 version 1.3.0 or higher is required to use this component.
{% endhint %}

{% hint style="warning" %}
**Important:** The Cover Component will only work for ranged abilities. If your AI has melee abilities, you will need to ensure your melee abilities have the Condition Module enabled with the Condition Type set to Distance From Target and Value Comparison Type set to Less Than. High priority should also be disabled. This will allow the AI to only use its melee abilities if their current target is within your set range. **If this is not done for your melee abilities, your AI may attempt to run to its current target's position.**
{% endhint %}

{% hint style="warning" %}
**Important:** The Cover Component is currently only compatible with Weapon Type 1. It is not recommended it is used with AI that have multiple weapon types. Support for this will be added with a future update.
{% endhint %}

## Setting up the Cover Component

The Cover Component gives AI the ability to search for Cover Nodes and use their positions for cover and attacking. Upon detecting a Cover Node, an AI will travel to it and rotate towards their current target. Depending on the setting for the Cover Node, the AI will either stand, crouch then attack for the set Attack Seconds, or crouch and repeatedly peak based on its Peak Times. This can help AI feel more intelligent and challenging for players and other AI to fight. There are various settings to control how your AI react when they are active on a Cover Node. &#x20;

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FkdcW9kadIAAgEjF33a66%2FCover%20Demonstration.gif?alt=media&#x26;token=bf9ed4d6-1639-4509-98d9-9d5976b75b4a" alt=""><figcaption></figcaption></figure>

### Assigning Cover Animations

You should first assign an AI's Cover Animations. This can be done through an AI's Animation Profile and opening the Combat Cover Animations foldout. Here, you will be able to assign a Cover Idle and a Cover Hit animation.

{% hint style="danger" %}
**Required: If you are using an AI created from an update prior to version 1.3.0**, will need to regenerate your Animation Profile in order to have the new Cover States added. <mark style="background-color:orange;">Not doing so will not allow the cover animations to play or be assigned to the Animator Controller.</mark> This can be done by [Regenerating your Animator Controller](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/emerald-profiles-and-objects/animation-profile/regenerate-animator-controllers). This will update your Animator Controller to the newest version and apply the missing Cover States.
{% endhint %}

{% hint style="warning" %}
**Important:** It is highly recommended that some type of crouch idle and crouch hit animation are used. This is to allow the most flexible cover system with not requiring specific animations. This is demonstrated in the above gif.
{% endhint %}

{% hint style="danger" %}
**Important:** If you do not have a crouch animation, you can leave these blank, but you will need to ensure all your [Cover Nodes](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/emerald-components-optional/cover-component/setting-up-cover-nodes) use the [Stand Cover Type](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/emerald-components-optional/cover-component/setting-up-cover-nodes#stand), which bypasses the need for a crouch animation. **If you do not do this, your AI will glitch do to the lack of cover animations.** <mark style="background-color:orange;">This is only necessary if you do not have crouch animations.</mark>
{% endhint %}

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2F7bgOS7KImPI9DTGvysw5%2FCoverAnimations.png?alt=media&#x26;token=ac080598-02df-4b3c-af86-20d0c2f12184" alt=""><figcaption></figcaption></figure>

### Assigning a Cover Node LayerMask

The first thing you will need to do is assign a LayerMask for your Cover Nodes. This allows the Cover Component to efficiently search for objects only using the specified layers. These layers should be exclusively used for your Cover Nodes. It it recommended to only use 1 to keep the setup and management as easy as possible. For this tutorial, the Cover layer is being used.

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2Fmlu7ctRKW1liIzCCP6w7%2FCoverNodeLayerMask.png?alt=media&#x26;token=b5c209d3-d16e-4e1a-984b-42501672b41c" alt=""><figcaption></figcaption></figure>

### Adjusting the Cover Settings

The rest of the settings can be customized as needed. Each setting has a description of its functionality. It's worth noting that only one AI can use a Cover Node at a time. Emerald AI and its Cover Component manages this automatically.

{% hint style="info" %}
**Note:** It is recommended that you have a relatively high Attack Distance for your ranged attacks. If your Attack Distance is too low, the AI may attempt to get closer due to them being out of range. These are adjustable through the [Combat Component](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/emerald-components-required/combat-component).
{% endhint %}

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FePgLDPaOZFZRHUXG9koy%2FCoverComponentSettings.png?alt=media&#x26;token=99e32d52-25e4-4263-871b-215b8ba2bb07" alt=""><figcaption></figcaption></figure>
