# Damaging an AI

All damage is handled through an interface script called IDamagable. This script acts like a bridge that allows damage calls to be received by any script that uses the IDamageable interface. This is important for custom character controllers as users can then receive the damage call to then damage their character controller's health.

If you’d like to apply damage to an AI directly, for something like a custom character controller, you can do so with the code below. YourTargetReference would be the collision or or target source that you would like to damage.

The damage function through the IDamageable interface script looks like this. DamageAmount is the amount of damage you would like to deal to the referenced target. The AttackerTransform is the transform source of the attacker (such as the player). The RagdollForce is the amount of force that will be applied to the referenced target's ragdoll components on death.

```csharp
Damage(int DamageAmount, Transform AttackerTransform, int RagdollForce)
```

{% hint style="warning" %}
**Important:** It is very important that the AttackerTransform is the correct source. This should be the transform that holds your player controller's health. Not getting this correct can lead to detection issues.
{% endhint %}

Assume you get a reference to a target hit with a collision or raycast and it's cached as YourTargetReference. Check to see if IDamageable exists on the target object. If it does, call the damage function.

```csharp
//Damages an AI to the YourTargetReference object
EmeraldAI.IDamageable m_IDamageable = YourTargetReference.GetComponent<EmeraldAI.IDamageable>();

if (m_IDamageable != null)
{
   m_IDamageable.Damage(DamageAmount, transform, 400);
}
```


---

# 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://black-horizon-studios.gitbook.io/emerald-ai-wiki/api/damaging-an-ai.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.
