> For the complete documentation index, see [llms.txt](https://distubredone322.gitbook.io/custom-vehicle-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://distubredone322.gitbook.io/custom-vehicle-controller/guides/vehicle-damage-system/part-damage-handler.md).

# Part Damage Handler

PartDamageHandler is a component responsible for keeping track of the individual part's health points, reduce health on collision and create the "danging" and "detachment" effect under certain condition.

### 1. Add the component and assign the controller

<div align="left"><figure><img src="/files/wyKShJNvokfOgoFkNr1K" alt="" width="440"><figcaption></figcaption></figure></div>

### 2. Reference this component to the VehicleDamageController

<div align="left"><figure><img src="/files/0HRVB2MVVWcbvFpTFHwL" alt="" width="431"><figcaption></figcaption></figure></div>

### 3. Add the new Damagable Vehicle Part

<div align="left"><figure><img src="/files/dyX15cXv6PCYMx7GQ7dH" alt="" width="410"><figcaption></figcaption></figure></div>

1. Give this part a name for easier identification in the list

<div align="left"><figure><img src="/files/0LRPowwTRBG9wYHISjVF" alt="" width="405"><figcaption></figcaption></figure></div>

2. Assign a Transform with the actual part (for example, the transform with the Spoiler mesh)

<div align="left"><figure><img src="/files/jVXIYUcYlDuIss543gg6" alt=""><figcaption></figcaption></figure></div>

3. Optionally (assign the pivot points)

<div align="left"><figure><img src="/files/r54Gj9LFIksKHrCSt7Ke" alt="" width="361"><figcaption></figcaption></figure></div>

Pivot points are used for the "dangling effect. The part will be parented to the furthest pivot point when the health will be depleted.

4. Select what Transforms will be taken into calculation when deciding if the part has suffered any damage after collision

<div align="left"><figure><img src="/files/sxelghN09JXsy4FFmyHx" alt="" width="362"><figcaption></figcaption></figure></div>

For example, if you wanted to create a damageable hood that will be dangling after collision, you would have a Pivot point near the window for the correct rotation, and the Part Transform would be in the front of the car so that the front collisions would be close enough to this Transform. In this case, you would select "Part Transform".

5. Set the initial health points.

<div align="left"><figure><img src="/files/V0DKwnr8yyMRlsT3MtEo" alt="" width="360"><figcaption></figcaption></figure></div>

{% hint style="info" %}
The "body strength" property on the VehicleDamageController affects the amount of damage the parts suffer.

You can see how much approximately collisions deal damage by enabling the "Debug" mode of the inspector. The "Damage Sustained" property will be revealed, that will show you the numbers in play mode.
{% endhint %}

6. (Optionally) Set up the dangling effect

<div align="left"><figure><img src="/files/euZV2GFzPxRGV9TX8RI9" alt="" width="363"><figcaption></figcaption></figure></div>

| Property               | Description                                                                                                                                                                      |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Min Speed For Dangling | The minimum speed required for effect to start growing.                                                                                                                          |
| Dange Max Effect Speed | The speed at which effect will be maxxed out.                                                                                                                                    |
| Dangle Rate            | The amount of back and forth rotations between the part's original rotation and the "Max Rotation" property of the Pivot Point the part was parented to (at max effect strength) |

Return to the Pivot Points array and set the "Max Rotation" values to your liking.

<div align="left"><figure><img src="/files/oJ3IsDjqr5F5dPryVV8i" alt="" width="368"><figcaption></figcaption></figure></div>

7. (Optionally) Set up the detachment effect

The detachment can occur when the vehicle suffered enough damage or when the vehicle has suffered enough damage and moves at high enough speed.

<div align="left"><figure><img src="/files/QO3eVb4fFOsOFaZsMGgu" alt="" width="367"><figcaption></figcaption></figure></div>

Select at least 1 of those conditions. If "Detach at High Speed" has been selected, "Detach Speed" property will be shown.

When detached, a Rigidbody will be added to the part. You can optionally set the flag to add BoxCollider as well.

In 5 seconds after the detachment, the part's gameObject will be set inactive.

8. (Optionally) Subscribe to events

<div align="left"><figure><img src="/files/B3QhxySZ9vwLzNYt9pvl" alt="" width="380"><figcaption></figcaption></figure></div>
