> For the complete documentation index, see [llms.txt](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://black-horizon-studios.gitbook.io/emerald-ai-wiki/api/damaging-an-ai.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://black-horizon-studios.gitbook.io/emerald-ai-wiki/api/damaging-an-ai.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
