⚔️MDamager
Last updated AC v1.5.3
Overview
This component is the core class used to affect character Stats, react and interact with other characters and objects in a scene.
It implements the IMDamager and IInteractor interfaces.
MAttack Trigger, MMelee, MProjectile, MShooteable, MExplosion and MBow inherit from MDamager.
E.g. if an Animal is affected by any of the Damager components, the Health Stat will be reduced and the Animal will react by playing a Damage Mode animation.

How it Works
When a Damager registers a collider it:
Filters it against Hit Layer, Trigger Interaction, Tags, Don't hit Owner and, when enabled, Prevent Duplicate Damage.
Rolls Miss Chance. On a miss it invokes On Attack Missed and stops.
Rolls Critical Chance. On a critical it multiplies the Stat Modifier value by the Critical Multiplier and invokes On Critical.
Finds a Damageable and applies the Stat Modifier to its Stats, carrying the Element with it.
Applies a force to the hit Rigidbody, plays the Hit Effect from the Surface Effects asset, and invokes On Hit, On Hit Position and, when the target is an Interactable, On Hit Interactable.
General
Active
Enable/Disable the Damager.
Index
Index of the Damager. Often used by the Animator to know which Damager to enable/disable from an animation.
Hit Layer
Layers to interact with. By default it is set to affect only the Animal layer. Right-click the field for Get Layer from Root.
Tags
Malbers Tags to filter what the Damager can hit. Leave it empty to hit everything on the Hit Layer.
Prevent Duplicate Damage
Prevents damaging the same Damageable twice within the same attack. Use it on wide or fast Attack Triggers that can register the same target on several frames.
Trigger Interaction
What the Damager does with Triggers: Collide or Ignore.
Attack Direction
On — the attack direction is calculated from the Damager's movement.
Off — the attack direction is the character's forward direction.
This direction drives the physics force and is passed to the Damageable so it can pick a directional hit reaction.
Don't hit Owner
When the Damager uses Raycast or OnTriggerEnter it can register colliders inside its own hierarchy. With this option enabled those colliders are ignored.
Owner
By default the Owner is the root of the hierarchy, but it can be set manually to another GameObject. If it is null it is resolved again to the root. Right-click the field for Find Owner.
Debug
The bug icon next to Active. Logs every hit, miss, critical and profile change.
Physics Force

When a Damager registers a collider it applies a force to the attached Rigidbody. The force used is a random value between Min and Max.
Min Force
Minimum force to apply to a hit Rigidbody.
Max Force
Maximum force to apply to a hit Rigidbody.
Force Mode
Type of force to apply on the ApplyForce() method. Default is Velocity Change.
Critical Damage

Critical damage applies a chance to increase or decrease the final value of the Stat Modifier.
Chance [0-1]
Probability of doing critical damage. 1 means always critical.
Mult
The Stat Modifier value is multiplied by this value when the critical roll succeeds. Default is 2.
Miss Chance
Probability of missing the attack entirely, from 0 to 1. 1 means it will always miss. A miss applies no damage, no force and no effect, and invokes On Attack Missed with the target GameObject.
Damage

When a Damager registers a collider it finds a Stats component in its hierarchy and applies the modification to a Stat.
Stat Modifier
Stat modification applied on the Damager receiver. For more info see Stat Modifier. Right-click the field for Set Default Damage.
Pure Damage
When true the Damage receiver (MDamageable) ignores its Profile Multiplier and its Element Multipliers, resulting in pure damage.
Element
Type of elemental damage the Damager can inflict (Fire, Ice, Poison...). The Damageable can multiply or resist the damage based on this Element, unless Pure Damage is on.
Interactions

Custom Reaction
A Reaction applied on the target instead of the Damageable's own default reaction. Leave it empty to let the Damageable use its default Animal Reaction.
Interact
If the damage receiver has an Interactable component, the Damager will interact with it, sending the Interactor ID value.
Interactor ID
Index sent to the Interactable. Only shown when Interact is on.
Effects
Audio Source
Audio Source used to play the hit sound taken from the Surface Effects asset. When it is empty, one is found or created on the Damager at runtime.
Hit Effects
A Surface Effects asset. On impact the Damager picks the effect matching the surface it hit, positions and orients it with the hit point and normal, and plays it. Entry [0] of the asset is used as the default when no surface matches.
Effect Duration
Seconds before the Hit Effect is released back to its pool. Only shown when a Surface Effects asset is assigned.
Stop Animator
A hit-stop effect: the Damager slows down an Animator for a moment on impact.
Animator Stop Time
Seconds the Animator stays slowed down. If it is zero, stopping the Animator is skipped and the other two fields are hidden.
Animator Speed
Animator speed while it is stopped. Default is 0.05.
Animator
The Animator to slow down. Right-click the field for Find Animator and Clear Animator.
Damager Profiles
Profiles let one Damager carry several sets of values and swap between them per attack: a light attack and a heavy attack on the same sword, or a charged shot on the same bow.
Each profile has a Name and a Modify flag mask choosing which groups of values it overrides. Only the checked groups are drawn and applied:
Damage
Stat Modifier, Pure Damage
Interact
Interact, Interactor ID
Reaction
React, Custom Reaction
Critical Chance
Chance, Mult, Miss Chance
Force
Min Force, Max Force
Elemental Damage
Element
Profiles are selected by index through DoDamage(bool, int profileIndex):
0restores the Default Profile, the snapshot of the values authored on the component.1..nappliesProfiles[index - 1].
Every change invokes On Profile Changed with the new index. Super Item Action processors use this to pick a profile per attack.
[Insert Image - The Damager Profiles reorderable list with a profile expanded and its Modify flags]
Events
On Hit
Invoked when the Damager hits a valid target. Sends the target Transform.
On Attack Missed
Invoked when the Miss Chance roll caused the attack to miss. Sends the target GameObject.
On Hit Position
Invoked on a hit. Sends the Vector3 point of contact.
On Hit Interactable
Invoked when the target was an Interactable. Sends the Interactable Index.
On Profile Changed
Invoked when the active Damager Profile changes. Sends the new profile index.
On Critical
Invoked when the critical roll succeeded on a hit.
Public Methods
DoDamage(bool)/DoDamage(bool, int profileIndex)— enable or disable the Damager, optionally switching Profile.SetDamageMultiplier(float)— multiply the Stat Modifier value applied on the next hits.SetOwner(GameObject)/SetOwner(Transform)— change the Owner at runtime.Stat_SetMaxValue(float)/Stat_SetMinValue(float)— change the Stat Modifier range.SetDefaultProfile()— snapshot the current values as the Default Profile.GetProfile()— build a Damager Profile from the current values.
Properties: Active, Index, ID (the Interactor ID), UserGo (the Owner), OwnerStats, Force, MinForce, MaxForce, HitPosition, HitRotation, IsCritical, IgnoreTransform.
Last updated