> 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/mdamager.md).

# MDamager

Last updated AC v1.5.3

## Overview

This component is the core class used to affect character Stats, react and interact with other characters and objects in a scene.

It implements the **IMDamager** and **IInteractor** interfaces.

[MAttack Trigger](/animal-controller/secondary-components/mdamager/mattack-trigger.md), MMelee, [MProjectile](/animal-controller/secondary-components/mdamager/mprojectile.md), MShooteable, [MExplosion](/animal-controller/secondary-components/mdamager/mexplosion.md) and MBow inherit from **MDamager**.

{% hint style="info" %}

### This component is abstract and is not meant to be used on its own

### Use MAttack Trigger or MProjectile instead

{% endhint %}

E.g. if an Animal is affected by any of the **Damager** components, the Health Stat will be reduced and the Animal will react by playing a Damage Mode animation.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MSeIPLnXvzlm1uO9V7J%2F-MSeIi9q8eW-jWAt6uKq%2Fimage.png?alt=media\&token=dff47b3a-a2fd-46e5-953f-3194009e8cd8)

{% hint style="success" %}

## All these parameters are found in every child component, plus some extra ones

{% endhint %}

## How it Works

When a Damager registers a collider it:

1. Filters it against **Hit Layer**, **Trigger Interaction**, **Tags**, **Don't hit Owner** and, when enabled, **Prevent Duplicate Damage**.
2. Rolls **Miss Chance**. On a miss it invokes **On Attack Missed** and stops.
3. Rolls **Critical Chance**. On a critical it multiplies the Stat Modifier value by the **Critical Multiplier** and invokes **On Critical**.
4. Finds a [Damageable](/animal-controller/secondary-components/mdamageable.md) and applies the **Stat Modifier** to its [Stats](/animal-controller/global-components/stats.md), carrying the **Element** with it.
5. Applies a force to the hit Rigidbody, plays the **Hit Effect** from the Surface Effects asset, and invokes **On Hit**, **On Hit Position** and, when the target is an Interactable, **On Hit Interactable**.

## General

### Active

Enable/Disable the Damager.

### Index

Index of the Damager. Often used by the Animator to know which Damager to enable/disable from an animation.

{% hint style="success" %}
Usually Animals have more than one Attack Trigger: Horns, Mouth, Claws, Feet, Swords... Each attack can use this index to activate the proper Damager while playing the animation.
{% endhint %}

### Hit Layer

Layers to interact with. By default it is set to affect only the Animal layer. Right-click the field for **Get Layer from Root**.

### Tags

Malbers [Tags](/animal-controller/scriptable-architecture/scriptables/tags.md) to filter what the Damager can hit. Leave it empty to hit everything on the Hit Layer.

### Prevent Duplicate Damage

Prevents damaging the same Damageable twice within the same attack. Use it on wide or fast Attack Triggers that can register the same target on several frames.

### Trigger Interaction

What the Damager does with Triggers: **Collide** or **Ignore**.

### Attack Direction

* **On** — the attack direction is calculated from the Damager's movement.
* **Off** — the attack direction is the character's forward direction.

This direction drives the physics force and is passed to the Damageable so it can pick a directional hit reaction.

### Don't hit Owner

When the Damager uses **Raycast** or **OnTriggerEnter** it can register colliders inside its own hierarchy. With this option enabled those colliders are ignored.

### Owner

By default the Owner is the root of the hierarchy, but it can be set manually to another GameObject. If it is null it is resolved again to the root. Right-click the field for **Find Owner**.

### Debug

The bug icon next to **Active**. Logs every hit, miss, critical and profile change.

## Physics Force

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MSe3aYXbUniJhgxlvbZ%2F-MSe611haX9fm6AYA-KI%2Fimage.png?alt=media\&token=c4e5d65c-88ef-410d-a0e8-455f4de1d71d)

When a Damager registers a collider it applies a force to the attached Rigidbody. The force used is a random value between Min and Max.

### Min Force

Minimum force to apply to a hit Rigidbody.

### Max Force

Maximum force to apply to a hit Rigidbody.

### Force Mode

Type of force to apply on the `ApplyForce()` method. Default is **Velocity Change**.

## Critical Damage

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MSeKJ-fh-veoiyFbDIU%2F-MSeKZ5BF7wNRFw5l5Fe%2Fimage.png?alt=media\&token=103143ef-d4b9-40bb-80b3-f5a357b49701)

Critical damage applies a chance to increase or decrease the final value of the Stat Modifier.

### Chance \[0-1]

Probability of doing critical damage. `1` means always critical.

### Mult

The Stat Modifier value is multiplied by this value when the critical roll succeeds. Default is `2`.

### Miss Chance

Probability of missing the attack entirely, from 0 to 1. `1` means it will always miss. A miss applies no damage, no force and no effect, and invokes **On Attack Missed** with the target GameObject.

## Damage

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MSe3aYXbUniJhgxlvbZ%2F-MSe8oGt-luOWbr1M8qV%2Fimage.png?alt=media\&token=7e6afe96-e0e4-471e-afe9-fceb734c959f)

When a Damager registers a collider it finds a Stats component in its hierarchy and applies the modification to a Stat.

### Stat Modifier

Stat modification applied on the Damager receiver. For more info see [Stat Modifier](/animal-controller/global-components/stats/stat-modifiers.md). Right-click the field for **Set Default Damage**.

### Pure Damage

When true the Damage receiver ([MDamageable](/animal-controller/secondary-components/mdamageable.md)) ignores its Profile Multiplier **and** its Element Multipliers, resulting in pure damage.

### Element

Type of elemental damage the Damager can inflict (Fire, Ice, Poison...). The Damageable can multiply or resist the damage based on this Element, unless **Pure Damage** is on.

## Interactions

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MSeKJ-fh-veoiyFbDIU%2F-MSeL6tELp1ZmJh6Re2g%2Fimage.png?alt=media\&token=fbb678d4-e11b-4a77-b27a-4804d90d0bb8)

### Custom Reaction

A [Reaction](/animal-controller/main-components/reactions.md) applied on the target **instead of** the Damageable's own default reaction. Leave it empty to let the Damageable use its default Animal Reaction.

{% hint style="info" %}
This replaces the old **React** toggle. An empty Custom Reaction behaves like `React = true`; to suppress the reaction entirely, handle it on the Damageable instead.
{% endhint %}

### Interact

If the damage receiver has an [Interactable](/animal-controller/global-components/interactable.md) component, the Damager will interact with it, sending the **Interactor ID** value.

### Interactor ID

Index sent to the Interactable. Only shown when **Interact** is on.

## Effects

### Audio Source

Audio Source used to play the hit sound taken from the Surface Effects asset. When it is empty, one is found or created on the Damager at runtime.

### Hit Effects

A **Surface Effects** asset. On impact the Damager picks the effect matching the surface it hit, positions and orients it with the hit point and normal, and plays it. Entry `[0]` of the asset is used as the default when no surface matches.

{% hint style="info" %}
The separate **Hit Effect** prefab and **Hit Sound** fields were removed. The Surface Effects asset is now the only source for hit effects and hit sounds.
{% endhint %}

### Effect Duration

Seconds before the Hit Effect is released back to its pool. Only shown when a Surface Effects asset is assigned.

{% hint style="warning" %}
A duration of **0** means the effect is **never** released back to the pool — it must disable itself. Set a value or the pool will drain.
{% endhint %}

## Stop Animator

A hit-stop effect: the Damager slows down an Animator for a moment on impact.

### Animator Stop Time

Seconds the Animator stays slowed down. If it is zero, stopping the Animator is skipped and the other two fields are hidden.

### Animator Speed

Animator speed while it is stopped. Default is `0.05`.

### Animator

The Animator to slow down. Right-click the field for **Find Animator** and **Clear Animator**.

## Damager Profiles

Profiles let one Damager carry several sets of values and swap between them per attack: a light attack and a heavy attack on the same sword, or a charged shot on the same bow.

{% hint style="info" %}
The Profiles list is drawn by the child components that use it — [MAttack Trigger](/animal-controller/secondary-components/mdamager/mattack-trigger.md), MWeapon and MDamageable — not by MDamager itself.
{% endhint %}

Each profile has a **Name** and a **Modify** flag mask choosing which groups of values it overrides. Only the checked groups are drawn and applied:

| Modify flag      | Overrides                  |
| ---------------- | -------------------------- |
| Damage           | Stat Modifier, Pure Damage |
| Interact         | Interact, Interactor ID    |
| Reaction         | React, Custom Reaction     |
| Critical Chance  | Chance, Mult, Miss Chance  |
| Force            | Min Force, Max Force       |
| Elemental Damage | Element                    |

Profiles are selected by index through `DoDamage(bool, int profileIndex)`:

* `0` restores the **Default Profile**, the snapshot of the values authored on the component.
* `1..n` applies `Profiles[index - 1]`.

Every change invokes **On Profile Changed** with the new index. Super Item Action processors use this to pick a profile per attack.

`[Insert Image - The Damager Profiles reorderable list with a profile expanded and its Modify flags]`

## Events

### On Hit

Invoked when the Damager hits a valid target. Sends the target **Transform**.

### On Attack Missed

Invoked when the **Miss Chance** roll caused the attack to miss. Sends the target **GameObject**.

### On Hit Position

Invoked on a hit. Sends the **Vector3** point of contact.

### On Hit Interactable

Invoked when the target was an Interactable. Sends the Interactable **Index**.

### On Profile Changed

Invoked when the active Damager Profile changes. Sends the new profile **index**.

### On Critical

Invoked when the critical roll succeeded on a hit.

## Public Methods

* `DoDamage(bool)` / `DoDamage(bool, int profileIndex)` — enable or disable the Damager, optionally switching Profile.
* `SetDamageMultiplier(float)` — multiply the Stat Modifier value applied on the next hits.
* `SetOwner(GameObject)` / `SetOwner(Transform)` — change the Owner at runtime.
* `Stat_SetMaxValue(float)` / `Stat_SetMinValue(float)` — change the Stat Modifier range.
* `SetDefaultProfile()` — snapshot the current values as the Default Profile.
* `GetProfile()` — build a Damager Profile from the current values.

Properties: `Active`, `Index`, `ID` (the Interactor ID), `UserGo` (the Owner), `OwnerStats`, `Force`, `MinForce`, `MaxForce`, `HitPosition`, `HitRotation`, `IsCritical`, `IgnoreTransform`.
