Add Hitboxes and Weak Spots
π― Goal
Feed one health from several colliders, with weak spots that take more damage.
π§° What You Need
Healthon the root- A collider on each body part
Hitboxon each collider
πͺ Steps
Add colliders to the body parts
Give each part that can be hit its own GameObject with a collider, under the root that holds Health. For a character that’s usually the head, torso and limbs. Solid (non-trigger) colliders work with collision-based attacks such as projectiles.
Add a Hitbox to each collider
Add Add Component > Glowing Rifts > Modular Health > Hitbox to every collider. Each hitbox looks for the Health on its own GameObject or a parent on Awake, so they all feed the same health pool.
Set the damage multipliers
Set Damage Multiplier per part: 2 for a weak spot or headshot, 1 for normal, 0.5 for armor. A bullet of 25 then takes 50, 25 or 12.5 (health changes in whole numbers, so about 12).
React to hits per part
Hook a hitbox’s On Hit to feedback for that part only, such as a hit sound on the helmet or a spark from a Spawnable Effect. For feedback from any part, hook the Health’s On Damage Data Received instead.
π Inspector Settings
| Field | What it does | Set it to |
|---|---|---|
| Damage Multiplier | Damage multiplier for this hitbox | 2 weak spot, 1 normal, 0.5 armor |
| On Hit | Invoked when this hitbox receives a hit, with the damage after the multiplier | Part specific sounds or effects |
π§ͺ Example
The boss in the Hitbox Boss scene has one Health of 5000 on its root and eight spheres, each with a Hitbox set to 2, 1 or 0.5. Shooting a weak sphere takes the boss down four times faster than an armored one. Its Hitpoint listens to the health’s On Damage Data Received, so the number shows whichever sphere was hit.
π‘ Tips
- Once you add a hitbox anywhere in the hierarchy,
Healthno longer adds its own. If the root also has a collider that should take damage, add aHitboxto it too. - Disable a hitbox to make that part immune for a while. A disabled hitbox ignores hits.
- Attacks have to find the
Hitboxon the collider they hit (see Deal Damage From Your Scripts). Health Pickups go straight toHealth, so multipliers don’t apply to them. - To test multipliers, add a
Hitpointto the root and watch the numbers as you hit each part.