Damage / Hitboxes
Damage can be handled many different ways depending on your project scope and you should make a distinct choice about how you handle it.
If you don't want a complicated structure then you don't need to do anything other than make sure you have at least one collider and reference it on the ProdigyAgent
class.
If you want location based damage for a more unique gameplay system you have in mind, then you should read on about how Strike Nodes work. Note that this is somewhat pointless for Top Down games since aiming is extremely loose compared to FPS games - so the computational cost in doing location based damage might not be worth it for you. It really just depends on your game design, though.
Relevant Components
AgentAttributes
, AgentVitals
, IDamageable
, StrikeNode
, StrikePointData
, ReactToDamage
, ThatHurtTrigger
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 (for instance the Character Controller component) to capture damage as you can 10 (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'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 (Ragdoll 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.
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.
Bottom line
The bottom line is that you have the traditional single collider or a deep location based system to work with and choosing one up front is important because it affects a lot of design choices on prefabs when it comes to colliders (projectiles, hitscans, and any layermask honestly), really changes how you define and assign your layers and may not be worth the trouble for you and your game type but nonetheless it's here for you to use if you need a deep location based system.
Work is in progress on this page
Last updated