Recipes & Workflows
Recipes & Workflows
Practical, copy‑paste guides for the most common scenarios. Pick the one that matches your use‑case and you’ll be reacting in minutes.
5.1 Animating a Humanoid Character
Goal: Add subtle chest‑and‑head flinch to a third‑person hero.
Add Components
HitReactionController
on the root.BodyPartReactor
on Chest and Head bones.
Assign Profiles
Chest → Light Hit (rotation only).
Head → Light Hit (rotation + small translation).
Animator Layer
Create Layer 1 – Reactions (Override, Weight 1). No clips needed.
Test
Drag the FPS Gun prefab into the scene and shoot at the hero.
Adjust Rotation Strength Z on the Head profile to ≈2° to avoid dizzy spins.
Pro Tip: If your rig already leans forward while running, enable Offsets From Current Pose on both reactors to prevent double‑bending.
5.2 Adding Reactions to Props / Creatures
Example: A hanging lantern that swings when hit.
Place
BodyPartReactor
on the lantern mesh (no Animator required).Uncheck Additive so the offset fully replaces the static pose.
Create a Lantern Swing profile:
Reaction Duration = 1 s, Blend‑In = 2, Blend‑Out = 1.
Rotation Strength = (0,20,0) — allow only yaw.
Rotation Axis Mask = (0,1,0).
Fire a projectile at the lantern → it now swings procedurally.
No collider? Add a small sphere collider so
HitReactionTrigger
can register impacts.
5.3 Custom Projectiles & Melee Weapons
Projectile (arrow)
Set Destroy On Hit to ✔️ so the arrow sticks once.
Melee Blade
Add a thin Trigger Collider along the sword edge.
Swap
OnCollisionEnter
→OnTriggerEnter
inside a copy ofHitReactionTrigger
(or convert collider to non‑trigger).Swing the sword: every overlap with a body‑part collider triggers
React()
.
5.4 Manual Calls to React()
Need full control (e.g., network sync, animation event)? Call the API directly.
1. Via Animation Event
In your attack animation, add an event at the exact frame of impact.
Event function:
2. Networked Hit
Sync the same parameters to all clients and call React()
locally—deterministic since math is purely transform‑based.
Next Up
Ready to dive deeper? Check out Advanced topics for axis locks, follow‑through chains, and performance tricks.
Last updated