Getting Started
Getting Started
🧠 How It Works
Damage flows through three pieces:
flowchart LR
A[Attack] -->|DamageData| B(Hitbox)
B -->|x Damage Multiplier| C(Health)
C --> D{Health Modifiers}
D -->|damage left| E[Health reduced]
- DamageData describes one hit: the amount, where it hit, the surface normal and who caused it.
- Hitbox sits on a collider. It scales the damage by its multiplier and forwards it to the
Healthon the same object or a parent. - Health lets its modifiers change or block the damage, then applies what’s left and raises its events.
All scripts are in the GlowingRifts.ModularHealthSystem namespace.
📦 Installation
- Import the package from the Unity Asset Store.
- The package is installed under
Assets/Glowing Rifts/Modular Health System. - TextMeshPro is needed for
Hitpointdamage numbers. Import its essentials if Unity asks.
🧱 Your First Damageable Object
Add Health
Select the root of your object (a player, an enemy, a crate) and add the Health component. Set Health to its starting and maximum health.
Add a Hitbox
Add Hitbox to every GameObject with a collider that should take damage. It finds the Health on itself or a parent automatically.
Hook the events
Use On Health Changed to drive a health bar (it passes health from 0 to 1) and On Death to play an effect or end the game.
Deal damage
Call hitbox.Hurt(...) from your attack, or drop a Contact Damage trigger in the scene to test it.
using GlowingRifts.ModularHealthSystem;
if (hit.collider.TryGetComponent(out Hitbox hitbox))
{
hitbox.Hurt(new DamageData
{
damagePoints = 25f,
hitPoint = hit.point,
hitNormal = hit.normal,
instigator = gameObject,
});
}Tip
Turn off Destroy On Death on players, then call ResetHealth() when they respawn.