ProceduralHitReactions
  • Welcome
  • Getting Started'
    • Getting Started
    • Core Concepts
  • Recipes & Workflows
  • Advanced
  • Modules
    • Reaction Profiles
    • BodyPartReactor
    • HitReactionController
    • HitReactionTrigger
  • Extra
    • Troubleshooting & FAQ
Powered by GitBook
On this page
  • Recipes & Workflows
  • 5.1 Animating a Humanoid Character
  • 5.2 Adding Reactions to Props / Creatures
  • 5.3 Custom Projectiles & Melee Weapons
  • 5.4 Manual Calls to React()

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.

  1. Add Components

    • HitReactionController on the root.

    • BodyPartReactor on Chest and Head bones.

  2. Assign Profiles

    • Chest → Light Hit (rotation only).

    • Head → Light Hit (rotation + small translation).

  3. Animator Layer

    • Create Layer 1 – Reactions (Override, Weight 1). No clips needed.

  4. 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.

  1. Place BodyPartReactor on the lantern mesh (no Animator required).

  2. Uncheck Additive so the offset fully replaces the static pose.

  3. 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).

  4. 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)

// When spawning your arrow prefab …
var arrow = Instantiate(arrowPrefab, originPos, originRot);
arrow.GetComponent<HitReactionTrigger>().reactLayers = LayerMask.GetMask("Characters");
arrow.GetComponent<Rigidbody>().velocity = originForward * 60f;

Set Destroy On Hit to ✔️ so the arrow sticks once.

Melee Blade

  1. Add a thin Trigger Collider along the sword edge.

  2. Swap OnCollisionEnter → OnTriggerEnter inside a copy of HitReactionTrigger (or convert collider to non‑trigger).

  3. 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

  1. In your attack animation, add an event at the exact frame of impact.

  2. Event function:

public void PunchEvent() {
    Vector3 dir = -transform.right; // fist travels left→right
    Vector3 point = fistTip.position;
    controller.React("Head", dir, point);
}

2. Networked Hit

Sync the same parameters to all clients and call React() locally—deterministic since math is purely transform‑based.

// On server
RpcReact(targetId, partName, dir, point);

// On each client
void RpcReact(int id, string part, Vector3 dir, Vector3 pt) {
    players[id].controller.React(part, dir, pt);
}

Next Up

Ready to dive deeper? Check out Advanced topics for axis locks, follow‑through chains, and performance tricks.

PreviousCore ConceptsNextAdvanced

Last updated 10 days ago