1
\$\begingroup\$

I've downloaded some 3D vehicle models that I bought from the Asset Store, because I don't know how to create 3d models.

These objects have different meshes for different vehicle parts: steering wheel, doors, body, lamp lights, hood etc.

I would like to simulate an explosion and apply physics impulses to each of the parts.

I've tried this flow:

  • Create a rigidbody for each vehicle part, set its weight and set:
    isKinematic = true; useGravity= false;

  • Create a mesh collider for each part and disable it

  • Create a main box collider for vehicle

When a bullet, or other explosive object, hits my vehicle, I've tried to use a script to enable these components on the parts: rigidbody (isKinematic = false, useGravity=true) and mesh collider, and, obviously, apply a force explosion.

The problem is that it's not possible to enable a mesh collider at runtime for performance reasons (it lags a lot, and this does not depend on PC/Hardware power, but depends from graphics pipeline).

So my question is: how can I simulate an explosion by applying forces to individual vehicle parts?

\$\endgroup\$
1
  • \$\begingroup\$ Turn the mesh collider from a trigger to normal collider when it explodes. \$\endgroup\$ Commented Oct 26, 2017 at 18:41

1 Answer 1

2
\$\begingroup\$

maybe my solution might not be good at all but worked for me
create three empty objects then put your car parts in two of them like this :

Holder = NotDestroyed , Destroyed
NotDestroyed = wheels , body , doors etc...
Destroyed = wheels , body , doors etc...

add ridgidbody and colliders to your mesh parts one by one.

then put NotDestroyed and Destroyed objects in your main object "Holder" , after that write a script and attach it to the Holder object that when anything like bullet or rocket touch collider of your car disable NotDestroyed and enable Destroyed ( be careful that position of NotDestroyed and Destroyed must exactly same as each other to achieve maximum result.
I have a script too you can use or try to read for better understanding of my answer.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DestroyObjects : MonoBehaviour {


// When aggresive object come touch collider
void OnTriggerEnter(Collider other)
{
    // compare tag to see if is correct object or not
    if (other.CompareTag("Player") || other.CompareTag("Cop"))
    {
        Obj_Destroy();
    }

}
// a function for disabling first holder and enbaling second holder (destroyed objects )
void Obj_Destroy()
{
    var Obj_Stand = transform.GetChild(0).gameObject;
    Obj_Stand.SetActive(false);
    var Obj_Des = transform.GetChild(1).gameObject;
    Obj_Des.SetActive(true);
}

}

I hope it helps.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .