> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/secondary-components/mdamageable.md).

# MDamageable

Last updated AC v1.5.3

## Overview

This component is in charge of connecting the Animal Controller to any [**Damager**](/animal-controller/secondary-components/mdamager.md) Component. It receives the Direction, the Stat to modify and the rest of the hit data, decides whether the hit is accepted, applies the Stat modification and plays an Animal Reaction according to the Damager information.

{% hint style="info" %}
This Component Requires a reference to the [**Stats**](/animal-controller/global-components/stats.md) Component
{% endhint %}

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FaMUiCJqSOx6EtfxxZ3OY%2Fimage.png?alt=media&#x26;token=31eba17d-1522-4450-b47d-e68c66b18392" alt=""><figcaption></figcaption></figure>

This component can be also used on child colliders to simulate specific damages.

E.g.

* You can add a **MDamageable** Component to the Head collider, and add a Multiplier of 2 to simulate Headshots that make twice the damage value.
* You can add a **MDamageable** Component to the Chest collider, Shield, or Head Helmet, add a Multiplier of 0.5 to simulate Defense, and only do half the Damage.

## Internal MDamageables

The component can also be set inside the Animal Hierarchy. This is very useful to create different damages and reactions to the animal.

For example, you can add an MDamageable component to the Head Collider, with a multiplier of 2 and a Reaction set to Play the Stun Action for 3 Seconds. If the Animal receives direct damage to the head collider, the Damage value will double and it will play a stun animation instead of the Damage Animations.

A child Damageable points to the character's main Damageable through its **Root**. Every event the child invokes is forwarded to the Root, and the Root's **Can Receive Damage** conditions apply to the child as well, so a rule such as "no damage while Dodging" is written once on the character and every hit box respects it.

{% embed url="<https://streamable.com/i6oubi>" %}

## How it Works

Every hit, whatever Damager sent it, goes through the same steps in this order. A step that stops the hit ends it completely: nothing below it runs.

```
Damager hits a collider that has a MDamageable
   │
   ├─ Component disabled?                  → stop (the character is immortal)
   ├─ Can Receive Damage conditions fail?  → On Damage Ignored, stop
   ├─ Store Hit Direction and Damager      (on this Damageable and on the Root)
   ├─ Attack rolled as Missed?             → On Damage Missed, stop
   ├─ Reactions                            Damager Reaction, then Critical / Custom / Damage Reaction
   ├─ Element Multiplier                   (skipped on Pure Damage)
   ├─ Profile Multiplier                   (skipped on Pure Damage)
   ├─ On Receiving Damage · On Damager · On Critical Damage · On Element Damage
   ├─ Modify the Stat                      → On Stat Empty when it reaches its minimum
   └─ Align to Damage
```

{% hint style="info" %}
**Pure Damage** (a Damager option) bypasses every multiplier on this side: the Profile Multiplier and the Element Multipliers. The Stat receives the Damager's value untouched.
{% endhint %}

## Parameters

## General

### Stats

Reference to the [**Stats**](/animal-controller/global-components/stats.md) component that receives the modification. Found automatically in the hierarchy when empty.

### Root

The root Damageable gameobject, if this is a child gameobject (see [Internal MDamageables](#internal-mdamageables)).

### Surface

Type of surface the damageable is e.g. Wood, Flesh, Metal etc. Damagers use it to pick the matching Hit Effect from their Surface Effects asset.

### Can Receive Damage

A list of [**Conditions**](/animal-controller/global-components/conditions.md) evaluated **before** any damage is applied. The conditions target is the **Character** (the component the Damage Reaction points to, usually the Animal). When the list fails, the hit is rejected: no reaction plays, the Damager receives no reaction, no event fires except **On Damage Ignored**, and the Stat is not modified.

\[Insert Image - MDamageable inspector showing the Can Receive Damage conditions box with an Animal Modes condition inside]

E.g. to make the character invulnerable while it is Dodging, add an `Animal ▸ Modes` condition with **Playing Mode** = `Dodge` and enable **Invert** on it, so the list is true only while the Dodge Mode is **not** playing.

{% hint style="info" %}
The conditions shown here belong to the **Default** Profile. Every other [Profile](#profiles) carries its own list, so a Block or Parry profile can use a different rule (e.g. ignore hits coming from the front) while it is active.
{% endhint %}

The Damager asks this Damageable first (`IMDamage.CanReceiveDamage()`), so **Attack Triggers** and **Melee** weapons treat a rejected hit like a miss: they skip their Interact, Physics, Stop Animator and Hit Effects. A dodged sword spawns no blood.

### Damage Reaction

Reaction to apply on the Animal when receiving Damage. By Default it will apply Mode Damage on the Animal, but you can change it and use any other [Animal Reaction](/animal-controller/main-components/reactions.md).

{% hint style="info" %}
You can add a **MDamageable** Component to the Head collider and change the reaction to activate a Stun Animation instead.
{% endhint %}

### Critical Reaction

The reaction to apply to the animal if a critical hit is achieved. It replaces the Damage Reaction and any custom reaction sent by the Damager.

### Damager Reaction

The reaction to apply to the one dealing the damage to this gameobject (the Damager's Owner). E.g. a Shield can push back the attacker.

### Ignore Damager Reaction

A Damager can bring its own custom reaction with the hit. When this option is enabled, that custom reaction is ignored and this Damageable plays its own **Damage Reaction** instead. Use it when the character must always react the same way no matter which weapon hit it. Each Profile has its own value.

### Multiplier

Value to apply an extra modification to the Stats to make Double Damage, if is set to greater than 1; or acts as Defense value if is set to a value between 0-1.

### Elements

A list of elements (Fire, Ice, Rock, Lightning etc.) and their associated damage multipliers that affect the damage values given to this gameobject. When the Damager's element matches an entry, the value is multiplied and **On Element Damage** is invoked.

{% embed url="<https://streamable.com/bu4e06>" %}

### Align to Damage

When enabled the animal will rotate toward the damage direction

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FS6Zie0MdubOgcX0L42cH%2Fimage.png?alt=media&#x26;token=f391c430-8ab6-4f58-93c2-141d1629ef4b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FSGZE6fcTzdTb5LOvdGjs%2FUnity_AyGkH1qlfa.gif?alt=media&#x26;token=6e9a9948-0f5c-478b-8ad2-249f2e17d5a8" alt=""><figcaption></figcaption></figure>

#### Only On Movement Zero

Align only when the character is not moving. Enabled by default, so a running character is not spun around by a hit.

#### Align Time

How long the alignment will last

#### Align Curve

Curve to smooth the trajectory of the alignment

#### Align Offset

For Animals in which the pivot may be set in the Hip position you can adjust the Rotation Pivot of the alignment with this value:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FvFAuxl7YMJJepcjeiQNo%2FUnity_JiPmhLltYl.gif?alt=media&#x26;token=12f5295f-e8a1-431a-b9c1-fab24ab18e4e" alt=""><figcaption></figcaption></figure>

## Profiles

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F2njsYFzJNix1GepYycxs%2Fimage.png?alt=media&#x26;token=c712dbcb-9052-418b-929b-2d12539df02f" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
To Activate a profile, call this function:

**`MDamageable.Profile_Set(`**<mark style="color:blue;">**`string`**</mark>**` `` ``profileName) `**

To reset to the default values, call:

**`MDamageable.Profile_Restore();`**
{% endhint %}

The damageable can use different profiles to change the way the animal can react to receiving damage.

E.g. You can activate a Profile when the Character has a New Armor, and it changes the way the Damage is done. So the character will receive half the damage.

Or you can change the Profile to Heavy Damage Animations if the Animal is in a Wounded stance.

{% embed url="<https://streamable.com/pthi6g>" %}

### Name

The name of the profile. Passing `"Default"` (or an empty name) to `Profile_Set` restores the Default profile.

Every profile carries its own copy of these General parameters:

| Parameter                            | Notes                                                             |
| ------------------------------------ | ----------------------------------------------------------------- |
| Surface                              | Hit Effect surface while the profile is active                    |
| Multiplier                           | Profile damage multiplier                                         |
| Align To Damage                      | Whether the character turns toward the hit                        |
| Ignore Damager Reaction              | Force this profile's own Damage Reaction                          |
| Can Receive Damage                   | Conditions checked before any damage while this profile is active |
| Damage / Critical / Damager Reaction | Reactions used while the profile is active                        |
| Elements                             | Element multipliers while the profile is active                   |
| On Profile Enter / On Profile Exit   | Optional events, shown when **Events** is enabled on the profile  |

The values on the General tab are the **Default** profile. Its Enter and Exit events live on the Events tab as **On Profile Default Enter / Exit**.

## Events

### On Receiving Damage (Float)

Invoked when the Damageable receives damage. Sends the final value of the Stat modification, after the Element and Profile multipliers.

### On Critical Damage

Invoked if the Damage received is Critical.

### On Damager (Gameobject)

This is invoked when a Damage is received. Use it to know who did the Damage.

### On Element Damage (Int)

Invoked when receiving elemental damage (Wood, Fire, Ice, Electric etc). Sends the Element ID.

### On Stat Empty (Int)

Invoked when the modified Stat reaches its minimum value with this hit. Sends the Stat ID. Use it for kill confirmations from a specific hit box.

### On Damage Ignored (Gameobject)

Invoked when the **Can Receive Damage** conditions reject a hit. Sends the Damager. Use it to play a dodge or parry effect, or to notify the attacker.

### On Damage Missed (Gameobject)

Invoked when the attack was rolled as **Missed** by the Damager's Miss Chance. Sends the Damager. A missed hit plays no reaction and leaves the Stat untouched; the **Floating Numbers** component listens to this event to show its *Missed!* text.

### On Profile Default Enter / On Profile Default Exit

Invoked when the Default profile becomes active or is replaced by another profile.

{% hint style="info" %}
All of these events are also invoked on the **Root** Damageable when they fire on a child Damageable.
{% endhint %}
