Search Unity

Split rigidbody into pieces

Discussion in 'Physics' started by Sumaccamus, Aug 29, 2015.

  1. Sumaccamus

    Sumaccamus

    Joined:
    Jul 5, 2014
    Posts:
    26
    hey my game development fellows :D

    i got stuck in a problem with the physics engine by unity. there is a barrel wich should break into pieces if it collides with another object faster than a specified velocity. now the problem is: how to know the torque of these pieces?

    say for example:
    -the barrels rigidbody rotates with a torque of (0.7,0.7,0)
    -than it collides
    -the velocity of the pieces can easily get by using "GetPointVelocity()"
    -now destroy the barrel itself, spawn the pieces and apply the velocity .

    it is important that it is physically correct.

    hope anyone has some ideas /suggestions.

    cheerio sumaccamus
     
  2. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    You men junks body parts ? You can try add physic on fly.

    Code (JavaScript):
    1. function AddPhysics()
    2. {
    3.     if (colliding)
    4.     {
    5.         if (physicObj.gameObject != null)
    6.         {
    7.             physicObj.gameObject.AddComponent(DestroyTimeScript);
    8.             physicObj.transform.DetachChildren();
    9.             physicObj.transform.parent = null;      
    10.                    
    11.             physicObj.gameObject.AddComponent(Rigidbody).interpolation = RigidbodyInterpolation.Interpolate;      
    12.             physicObj.gameObject.AddComponent(MeshCollider).convex = true;
    13.         }
    14.     }  
    15. }
    Hope help your needs.
     
  3. Sumaccamus

    Sumaccamus

    Joined:
    Jul 5, 2014
    Posts:
    26
    i don't get the point. :confused:
    not sure how this helps to find the correct torque.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Vector3 localangularvelocity = transform.InverseTransformDirection(rigidbody.angularVelocity);