- Home /
Best way to handle LOTS of potential rigidbodies?
So I'm building a rather large city in which I would like the buildings to be mostly destructable. The way I'm handling it at the moment is working fairly well but I'm not exactly a programmer so I wanted to see if I could be missing any methods of saving even more processing overhead.
At the moment I have a big static cube trigger in the exact dimensions of the building I need. I have a prefab of the same size tower that has been diced up into several hundred rigidbody pieces, (bound together with fixed joints) that spawns when the initial cube trigger is triggered.
When the player starts to destroy the building, pieces moving above a certain velocity spawn a one-shot particle cloud and destroy themselves which helps eliminate a fair bit of the overhead so far while remaining fairly satisfying visually.
Occlusion culling handles the initial trigger buildings pretty well.
So that's where I'm at so far. Perhaps I could limit the number of active rigidbodies allowed at any given time? Anything else? Even if you're not sure if it would work out visually I might be able to use it. I'm completely okay with "cheating" the way you would really expect everything to behave.
Thanks! -Seth
Occlusion culling probably won't do much for Physics. It's a rendering thing not a Physics thing so it shouldn't stop calculations on your rigidbodies.
Glad you like them. Don't forget to mark it the correct answer too though.
One thing you could look into is to use animations for the destruction of the buildings, to reduce the amount of physics calculations.
Answer by Peter G · May 16, 2011 at 11:26 PM
There isn't too much you can do if you must have all those rigid bodies. Increase the fixed time step if you can. That will reduce the frequency you have to recalculate the rigidbodies.
This would take some work to implement, but would definitely same some processing overhead. If you can, disable rigidbodies and colliders while they are falling. And manipulate the transform directly- basically just add gravity. Or at least disable the colliders.
Hey thanks for the tips! I haven't heard of increasing the fixed time step.. sounds good. I think I'll try the collider disabling as well and maybe when they collide with the ground have them spawn a couple collective "rubble piles" shrouded in dust for a moment.
Thanks for your help! :)
Answer by Ericool · Apr 01, 2015 at 09:19 PM
The thing is that you can enable or disable any component at any time , that means that if you are not shooting or whatever , none is enabled , but if you are , then the approximate region of where the collision should happen objects will enable their component. In you case it will activate the building , that should enable all small cubes collider component . Also , occlusion culling is great , but also check for mipmapping , lightmapping . Try to reduce what is unused the most . Try work with simple statement , not repeating where not needed .
Your answer
Follow this Question
Related Questions
MRUA implementation optimization issues 1 Answer
Rigidbody.MovePosition performance 1 Answer
Is a collider that enables/disables considered stationary? 2 Answers
Broadphase CD in Unity - pile of rigid bodies unsolved 0 Answers
Add 2d rigidbodies to moving objects to increase performance or not? 1 Answer