Using Location Based Damage - Black-Horizon-Studios/Emerald-AI GitHub Wiki

Using Location Based Damage

Location Based Damage (LBD) allows colliders within an AI to receive damage and have customizable damage multipliers, such as headshot doing more damage than hits to limbs. This is all done via a separate component, along with an easy to use editor, that will automatically get all colliders within an AI and allow you to customize the damage multiplier for each one. Accurate impact effects, based on the normal of the hit collider, are also possible with included easy to use API. Collisions with AI are also improved as all colliders within an AI will stay active and move according to the AI's current animation (instead of having one large box collider over the AI's mesh as what was done previously). To add LBD to an AI, please refer to the guide below.

Step 1

Select the AI you would like to add LBD to and add a LocationBasedDamage script by dragging said script onto the AI object or by using the Add Component button at the bottom of the AI within the inspector.

Step 2

Ensure that your AI has been setup through the Unity Ragdoll Wizard, or a 3rd Party ragdoll tool, so that there are colliders generated for each main bone transform within your AI. Press the Get Colliders button within the LBD editor to automatically get all colliders within the AI. You will then be able to apply a custom modifier to each detected collider within your AI.

A value of 1 will apply no changes to the damage received. Any multiplier greater than 1 will multiply the damage received by the multiplier of the hit collider. So, for example, if the collider hit gets a base damage of 20 and its multiplier is 5, the AI will receive 100 damage towards the Emerald AI agent's health. Values less than 1 can also be used and will reduce the damage received according to the multiplier. This can be useful for making AI harder to kill or needing to hit a "weak spot" in order to damage the AI.

Step 3

Emerald AI agents can automatically detect if an AI target has a LBD component. When this happens, the hit AI will be damaged according to the hit collider, its multiplier, and the damage received.

If you want your player to damage an LBD component, an extra step is required as damaging an LBD component is different than damaging the AI directly. To do this, you will need a reference to the AI collider hit, a reference to the LocationBasedDamageArea component, and a call the DamageArea function within the LocationBasedDamageArea component. The DamageArea parameters are the same as the EmeraldAISystem's Damage function to make the process easier.

//Damages an AI based off of the collider hit and its multiplier. In this example, a raycast was used to get a reference to the object hit.
if (hit.collider.GetComponent<LocationBasedDamageArea>())
{
   hit.collider.GetComponent<LocationBasedDamageArea>().DamageArea(DamageAmount, EmeraldAISystem.TargetType.Player, PlayerTransform, 400);
}

If you would like to create an impact effect at the position the AI's collider is hit, there's a built-in function to do so. All you need to do is use a raycast and pass the hit.point as the CreateImpactEffect Vector3 parameter. The Impact Effect that is used is based off of the AI hit and its Hit Effect List (Located under AI's Settings>Combat>Hit Effect). Note: Use Hit Effect must be enabled in order to use this feature.

hit.collider.GetComponent<EmeraldAI.LocationBasedDamageArea>().CreateImpactEffect(hit.point);