# Setting up the Weapon Collision Component

## Setting up the Weapon Collision Component

Now that the Weapon Collision Component has been applied to your AI's weapon object, you will need to adjust its size.

{% hint style="info" %}
Note: If you have not already applied the Weapon Collision Component to your AI's weapon object, please see the [Applying the Weapon Collision Component](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/emerald-components-optional/weapon-collision-component/applying-the-weapon-collision-component) section.
{% endhint %}

With the weapon's "Edit Collider" enabled, adjust the size of the collider to fit the area of your AI's weapon you'd like to cause damage.&#x20;

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FnQC5DLda2gEPSwrfuwCt%2FEnableCollisionAdjustment.png?alt=media&#x26;token=08e60081-4b72-4088-bcce-0fe8038af21f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FqBUrfOQgYpX9QoSUJx6Z%2FAdjustingWeaponCollisionCollider.gif?alt=media&#x26;token=3f204728-7093-4cd4-809c-0ae00f231708" alt=""><figcaption></figcaption></figure>

Next, open the Animation Viewer through your AI's Animation Profile. This will open the Animation Viewer and allow you to view your AI's animations within the scene view. Select one of your AI's attack animations through the Current Animation pulldown. Next, set the Event Type to Enable Weapon Type 1 Collider (or Type 2 depending on what weapon type your AI is using).

{% hint style="info" %}
Note: See the [Opening Animation Viewer](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/emerald-components-required/animation-component/opening-the-animation-viewer) section for a quick guide for opening the for your AI.
{% endhint %}

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FKRKqNDFw17K3WzgRmlQU%2FEnableWeaponCollisionEventType.png?alt=media&#x26;token=6a89fe8c-b8f0-45f7-997b-d7ad800cb5a8" alt=""><figcaption></figcaption></figure>

Find the frame you would like the weapon's collider to start being enabled. When you have found it, press the event button with the + mark. This will automatically add an Animation Event to your AI's animation to enable the weapon collider.

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2F2b25NbLQm7vu3mgq4tca%2FAddEnableWeaponCollisionEvent(BeforePresetText).png?alt=media&#x26;token=9cc3fda3-79a4-40c1-a157-58d63d8a9597" alt=""><figcaption></figcaption></figure>

You will need to assign your AI's weapon's name to the String parameter. This allows the event to know which weapon to enable.

{% hint style="warning" %}
**Important:** Ensure you type your AI's weapon's name exactly as it's shown or it will not be enabled.
{% endhint %}

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FKCBBqAlvzewtx0dYrMLg%2FAddEnableWeaponCollisionEvent(AddingWeaponName).png?alt=media&#x26;token=5f5e3b86-a1e2-427d-a407-0c039a622f2c" alt=""><figcaption></figcaption></figure>

Next, do the same thing, but this time, use the DisableWeaponCollider Animation Event and find the frame you'd like the weapon collider to be disabled.

{% hint style="warning" %}
**Important:** You will need to do this for each melee attack animation your AI is using. This process only needs to be done once. After these events have been created, they can be used by other AI who share an Animation Profile.
{% endhint %}

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2FVMLPVPnHCgSqKcvEm1Hv%2FAddDisableWeaponCollisionEvent.png?alt=media&#x26;token=c7d06db7-2bf1-449b-aa84-3bf9b1c6a32d" alt=""><figcaption></figcaption></figure>

Once you are finished, press the Apply Changes to save the Animation Events that were created.

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2F9W1S9jdgoTLDCtT57XTV%2FApplyAnimationViewerChanges.png?alt=media&#x26;token=d4c2d692-f7e2-425e-b8b7-cc3c92e187dd" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note:** Now that the needed Animation Events have been set up, there's still one more step below.
{% endhint %}

If you haven't already done so, you will need to add the Items Component to your AI. You can do this by searching for the EmeraldItems script and dragging it onto your AI.

<figure><img src="https://content.gitbook.com/content/v03IiZPaMe8fX49a9MnO/blobs/A8n1Oh1CCgQAxd9JVgtd/AddingTheItemsComponent.gif" alt=""><figcaption></figcaption></figure>

Next, open the Weapon Settings foldout and assign your AI's weapon to the Held slot. This should be the same weapon that you assigned in the Animation Event above.

{% hint style="warning" %}
**Important:** Ensure this is the same object with the same name as assigned above. If this is left blank, the Animation Event created above will not be able to work.
{% endhint %}

<figure><img src="https://4021441153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fv03IiZPaMe8fX49a9MnO%2Fuploads%2Fyn12188mb1rheeCNnPdy%2FAssigningWeaponToItemsComponent.png?alt=media&#x26;token=be0f8d84-788d-408b-9b26-2ea90ff3695b" alt=""><figcaption></figcaption></figure>

Test your AI against one of the included targets to ensure everything is working correctly and that the target is properly receiving damage. Keep in kind that this requires the weapon to physically hit a target. If an AI's weapon collider is unable to hit their target, you can adjust the size of the collider as needed.

{% hint style="info" %}
**Note:** You can watch the collider during runtime within the scene view and with [Unity's Gizmos enabled](https://docs.unity3d.com/Manual/GizmosMenu.html). However, this will only work if the AI is selected.
{% endhint %}
