Add Hitboxes and Weak Spots

Add Hitboxes and Weak Spots

🎯 Goal

Feed one health from several colliders, with weak spots that take more damage.

🧰 What You Need

  • Health on the root
  • A collider on each body part
  • Hitbox on 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

FieldWhat it doesSet it to
Damage MultiplierDamage multiplier for this hitbox2 weak spot, 1 normal, 0.5 armor
On HitInvoked when this hitbox receives a hit, with the damage after the multiplierPart 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, Health no longer adds its own. If the root also has a collider that should take damage, add a Hitbox to it too.
  • Disable a hitbox to make that part immune for a while. A disabled hitbox ignores hits.
  • Attacks have to find the Hitbox on the collider they hit (see Deal Damage From Your Scripts). Health Pickups go straight to Health, so multipliers don’t apply to them.
  • To test multipliers, add a Hitpoint to the root and watch the numbers as you hit each part.

πŸ”— Related