Explode.cs
Last updated
Last updated
Inlcuded with ACP is a script called Explode.cs.
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.
After adding the Explode component, right mouse click the title and select 'Get Meshes in Children'.
After finding all the mesh renderers in the children, you'll now have a list of them.
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
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 Rigidbody.AddExplosionForce(float explosionForce, Vector3 explosionPosition, float explosionRadius, float upwardsModifier = 0.0f, ForceMode mode = ForceMode.Force);
The various parameters are exposed in the inspector so you can manage easily test how the explosion will look
To test these values, at runtime right mouse click the component title and select 'Explode'.
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.
DoExplosion(Vector3 explosionPosition, float force = 10f, float radius = 5f, float upModifier = 10f);