> For the complete documentation index, see [llms.txt](https://ironsami-studio.gitbook.io/proceduralhitreactions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ironsami-studio.gitbook.io/proceduralhitreactions/modules/hitreactioncontroller.md).

# HitReactionController

## HitReactionController Inspector

`HitReactionController` is the **per-character hub** that receives `React()` calls and routes them to the matching `BodyPartReactor`. You’ll usually have **one controller per rig**—placed on the same GameObject that holds the Animator.

> **Add via:** *Component ▸ Hit Reactions ▸ Hit Reaction Controller* or automatically when you use the *Quick-Start* prefab helper.

***

### Inspector Reference

#### 1. Animator Settings

| Field              | Default           | Description                                                                                                                                               |
| ------------------ | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Animator**       | *(auto-assigned)* | Reference to the character’s `Animator`. Left blank? The component grabs `GetComponent<Animator>()` at runtime.                                           |
| **Reaction Layer** | `1`               | Index of the override layer that carries the additive pose. Must match the layer you created in the Animator Controller (weight is driven automatically). |

**Tip:** Keep the layer type set to **Override** and weight = **1** in the Animator Controller. The controller sets the weight back to 0 when no hit is active.

#### 2. Body Part Reactors

Drag every `BodyPartReactor` on the character into this list **once**. The order does not matter—lookup is done by name.

| Column           | Description                       |
| ---------------- | --------------------------------- |
| **Element \[ ]** | Reference to a `BodyPartReactor`. |

***

### How It Works

1. **React()** is called by a `HitReactionTrigger` (or your own code). Parameters:

   ```csharp
   React(string partName, Vector3 hitDir, Vector3 hitPoint);
   ```
2. The controller loops through `reactors[]`; when `part.name` matches `partName` (case-insensitive) it calls `part.React(hitDir, hitPoint)`.
3. Each frame during a hit, the controller copies the reactor’s **weight** to the configured Animator layer, keeping additive blending in sync.

Because all per-bone math is isolated in the reactor, the controller stays tiny—just a **router**.

***

### Public API Cheatsheet

```csharp
// Send a generic hit to the chest using projectile velocity
controller.React("Chest", bulletDir, contactPoint);

// Manual melee example using sword swing vector
var dir = swordTip.velocity.normalized;
controller.React("Head", dir, hitPos);
```

> **Performance:** `React()` is O(n) over the reactors list, but n is usually < 10. Call sites are event-based (collisions) so overhead is negligible.

***

### Best Practices

* **One controller per rig** – placing multiples on child props will double-blend the same bones.
* **Animator Controller setup** – dedicate a fresh layer; do **not** reuse your IK or upper-body layers.
* **Naming convention** – keep bone GameObject names unique per rig (e.g., "Chest", "Chest\_1"), or you’ll trigger the wrong reactor.
* **Pooling bullets?** Make sure pooled projectiles reset their `HitReactionTrigger` state so they don’t forward stale collisions.

***

#### Next Up

Finish the component set with **HitReactionTrigger Inspector**, or jump ahead to **Recipes & Workflows** to see this controller in action across projectiles, swords, and explosions.
