- Home /
Faking "Destructible" structures with groups of rigid bodies
I want to set up groups of prefabs with rigid bodies on them as structures, which can be "exploded" when a projectile collides with it.
I am able to get several rigid bodies reacting at once, but in order to be more efficient (and build a bigger "city"), I thought it might be a good Idea to set up some sort of trigger system so that the structures which are not being affected, will not add stress to the physics engine.
Essentially, the structures would be converted from a static object to a group of rigid body prefabs on collision. Is there a way to turn the physics for objects on and off like that? As a noob to scripting in general, I am unsure of how to go about setting this up... any help would be greatly appreciated. Thanks.
Answer by duck · Feb 09, 2010 at 05:31 PM
You might find that simply ensuring that all your unexploded rigidbody structures are sleeping is enough to get good performance out of the engine.
Sleeping rigidbodies cause very little performance drain. See the manual page for Rigidbody.Sleep.
Edit: Another nice touch can be to create physics joints between the rigidbodies with a fairly low break force, which means that structures can collapse more realistically rather than just "falling apart" when hit.
Thanks again Duck... this was exactly what I was looking for. :)
Answer by Ashkan_gc · Mar 08, 2010 at 02:27 PM
i added a feature request to feedback about what you want to do. i requested a feature to create destructible meshes. go to this link and vote for it please. the feature is not that hard to implement just a mesh spliting algorithm is needed so if we vote enough they'll add it. all physx needed features are currently supported in unity. http://feedback.unity3d.com/forums/15792-unity/suggestions/536687-destructible-meshes
Answer by efge · Feb 09, 2010 at 06:38 PM
I would suggest the 'trigger system' because you don't have to take care about the rigid-bodies and you get much better graphic performance for your large city. One simple box collider as a trigger per building or block with shared materials will reduce draw calls for the undestroyed part. When switching to destroyed or exploded you then could use other materials, add geometry like debris , ...
http://www.pixeluxentertainment.com/ ... just as a reference :-)
Answer by Ashkan_gc · Feb 09, 2010 at 08:18 PM
you can use another prefab of your object with rigidbodies attached and destroy your normal object and instantiate that rigidbody enabled one to destruct it. also you can add and remove rigidbody component but it's harder to adapt with changes and less reusable.