Design - Hitboxes
How to handle damage and getting hit in general.
Damage can be handled many different ways depending on your project scope and you should make a distinct choice about how you handle it.
Relevant Components
AgentAttributes
, AgentVitals
, IDamageable
, StrikeNode
, StrikePointData
Typical Setup
The architecture is 'location-based' by default. It's really just a matter of how many 'locations' you define. You can just as easily have 1 collider (The Controller) to capture damage as you can 100 (strike nodes).
Add any number of colliders you wish to an Agent's model.
Put these objects on the "StrikeNodes" layer.
Reference them to the appropriate
StrikePointData
entities.Reference the owning
AgentVitals
component on each of them.Set the layer of the
AgentVitals
object to something different, such as the "Agents" layer.
Now when you set your Weapon System's HitMask to only the "StrikeNodes" layer then they will make contact with these hitboxes, send damage messages through the IDamageable
interface and the StrikeNode
component will multiply it as designed and pass the new data to the AgentVitals
for processing. AoE and multi-hit situations are solved by referencing each contact's IDamageable.LifeId
for duplicate Id's. The LifeId
is guaranteed unique per each AgentVitals
component so you can easily and effectively understand if you have more than one contact on the same entity.
This is highly customizable, allowing for basic setups where an Agent has only one (or zero) StrikeNode
components pointing to the AgentVitals
, all the way to having a StrikeNode
for every limb and every equipped item model that may effect damage. (Shields!)
For example...
Scenario A (simple)
Root Character Object (
AgentVitals
) on "Agents" layerCharacter Model
Equipment models
Etc.
In this scenario it is extremely simple, the AgentVitals
captures all damage events through it's IDamageable
interface and would need to do processing on what equipment it has and how that effects damage.
Scenario B (complex)
Root Character Object (
AgentVitals
) on "Agents" layerCharacter Model
Leg (Ragdoll Collider/Rigidbody)
StrikeNode
(and large hitbox on "StrikeNodes" Layer)
Torso (Ragdoll Collider/Rigidbody)
StrikeNode
(and large hitbox on "StrikeNodes" Layer)
Head (Ragdoll Collider/Rigidbody)
StrikeNode
(and large hitbox on "StrikeNodes" Layer)
LeftPinkyToe (Radgoll Collider/Rigidbody)
StrikeNode
(and large hitbox on "StrikeNodes" Layer)
In this scenario we have a much more complex situation where there are many colliders on the character and ragdolls are supported. By putting the StrikeNode
objects and components as separate objects under the bones that they're connected to we can identify them on different layers and with different colliders. This is necessary because we probably always want our "hitbox" colliders to be larger than our more precise ragdoll colliders.
Weapons / Projectiles need to be setup to filter only the layers you want them to interact with, so the design path you want to use here is best to know early on.
All of the StrikeNode
components here would be pointing to the parent object's AgentVitals
component and just as easily forward damage events to it.
Each StrikeNode
is capable of processing and modifying damage prior to sending it to AgentVitals
so it's important to understand where and when you are adding/modifying damage. This is a design choice for you to make.
Work is in progress on this page
Last updated