# Explode.cs

Inlcuded with ACP is a script called Explode.cs.&#x20;

Add this component to the parent of your vehicle, find the mesh renders and tell it which type of collider you want to use for that mesh, now when the vehicle explodes using this class it will get a rigidbody and collider added.

### How to get Mesh Renderers

After adding the Explode component, right mouse click the title and select 'Get Meshes in Children'.

<figure><img src="https://1391598427-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcpQWpERugx5E3ZahgIme%2Fuploads%2FhHwv3gAGxKSFud2a0KlK%2FUnity_22FAtf8286.png?alt=media&#x26;token=d7850562-33dc-4e23-9f75-8b4e2a0a094d" alt=""><figcaption></figcaption></figure>

After finding all the mesh renderers in the children, you'll now have a list of them.

<figure><img src="https://1391598427-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcpQWpERugx5E3ZahgIme%2Fuploads%2FPDaAzTmBmcAgIUq9uS0u%2FUnity_GGxIW1mItB.png?alt=media&#x26;token=d39edb49-42f0-4259-bbad-f0d41bf5295b" alt=""><figcaption></figcaption></figure>

Expanding each element in the list, you'll see the following information for each one.

Name - the name of the GameObject the Mesh Render is on\
Mesh Renderer - a reference to the Mesh Renderer\
Mesh GameObject - a reference to the GameObject the Mesh Renderer is on\
Bools - four bools to set which collider to add

<figure><img src="https://1391598427-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcpQWpERugx5E3ZahgIme%2Fuploads%2Fm9MEEEL00qv79s1zSzvm%2FUnity_RW0ie1OyQD.png?alt=media&#x26;token=9d149222-3d1e-4478-8900-781cdc4109a0" alt=""><figcaption></figcaption></figure>

Go through each element and select which collider you wish to be added when the vehicle explodes. This is implemented in a smiple way and will only add one collider, so if you click Box and Sphere colliders, only the box collider will be added. The order is from top to bottom.

This class uses the method *<mark style="color:green;">Rigidbody</mark>.<mark style="color:yellow;">AddExplosionForce</mark>(<mark style="color:blue;">float</mark> explosionForce, <mark style="color:green;">Vector3</mark> explosionPosition, <mark style="color:blue;">float</mark> explosionRadius, <mark style="color:blue;">float</mark> upwardsModifier = 0.0f, <mark style="color:green;">ForceMode</mark> mode = ForceMode.Force);*

The various parameters are exposed in the inspector so you can manage easily test how the explosion will look

<figure><img src="https://1391598427-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcpQWpERugx5E3ZahgIme%2Fuploads%2FgJffeZsrUKL9R9l6utci%2FUnity_fRsOoMTtXh.png?alt=media&#x26;token=5a16c894-75fd-42d0-a78b-0dfcac5b113d" alt=""><figcaption></figcaption></figure>

To test these values, at runtime right mouse click the component title and select 'Explode'.

<figure><img src="https://1391598427-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcpQWpERugx5E3ZahgIme%2Fuploads%2FJ0rJqf3TClWBE5UbuwyE%2FUnity_4n7HkEwwS5.png?alt=media&#x26;token=21e5acde-f59c-4a04-bd7f-8e29acc0a2f5" alt=""><figcaption></figcaption></figure>

To explode the vehicle at runtime during gameplay, get a reference to Explode.cs and call the following public method, passing in the values you wish to use for the explosion.

*<mark style="color:yellow;">DoExplosion</mark>(<mark style="color:green;">Vector3</mark> explosionPosition, <mark style="color:blue;">float</mark> force = 10f, <mark style="color:blue;">float</mark> radius = 5f, <mark style="color:blue;">float</mark> upModifier = 10f);*
