Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question What's the best way to explode an already shattered 3D Object?

Discussion in 'Physics' started by Shiverkmusic, Feb 25, 2021.

  1. Shiverkmusic

    Shiverkmusic

    Joined:
    Jan 31, 2021
    Posts:
    12
    Hello.
    I've been trying to create an explosion effect that goes from the center of a 3D Object and expands, but i always end up with wierd behaviours (probably intended by design?).

    Here's what i have at the moment.

    The Script:

    Code (CSharp):
    1.    
    2.  
    3.     public MeshRenderer[] childArray;
    4.  
    5.     void Explode()
    6.     {
    7.  
    8.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    9.  
    10.         RaycastHit hit;
    11.  
    12.         if (Physics.Raycast(ray, out hit))
    13.         {
    14.  
    15.             if (hit.collider.CompareTag("Cube"))
    16.             {
    17.  
    18.                 GameObject x = ObjectPool3.current.GetPoolShattered();
    19.                 x.transform.position = hit.transform.position;
    20.                 x.SetActive(true);
    21.                 hit.collider.gameObject.SetActive(false);
    22.                
    23.                 childArray = x.GetComponentsInChildren<MeshRenderer>(); // i'm using this one in other section                    of the script, so i figured that would be better to just use this Array. I don't think the problem lies                      here.
    24.  
    25.                 foreach(MeshRenderer child in childArray)
    26.                 {
    27.  
    28.                     child.GetComponent<Rigidbody>().AddExplosionForce(50, x.transform.position, 4);
    29.  
    30.                 }
    31.  
    32.             }
    33.  
    34.         }
    35.  
    36.     }

    The result:
    The explosion position is in the center of the object but some shards of the object are almost unaffected.

    FormatFactory Registro de tela20210224_211143.gif

    What i've tried:

    Using AddExplosionForce with many variations of values, including 0 radius;
    Using AddExplosionForce with all the ForceModes;
    The best result i achieved just overlaping the two objects, shattered with children and the solid one, it collapsed on itself and exploded. Unfortunately using this way i can't ignore collision between the two types of objects from their respective pool.

    The question is:
    How can i explode the already shattered object from inside out and make a "normal" explosion effect without just overlaping them?

    Thanks!
     
    Last edited: Feb 25, 2021