- Home /
useAutoMass and child objects
Hello! Question is: I have an object with rigidbody2d, and useAutoMass checked.
Then I instantiate a bunch of prefabs, with colliders, but without rigidbodies, and make my main object their parent.
I assigned density for children prefabs by adding rigidbody, checking useAutoMass, assigning density, and then removing rigidbody Their density do not work, when I instantiate them. When I pause my scene, all numbers are there, as I wanted them to, but they work as if they have default density. They start to work properly after I reassign density to them, like this: Collider.density = Collider.density; but I wonder if there are less messy way to make it all work?
Answer by MelvMay · Apr 08, 2016 at 02:21 PM
Collider2D without a Rigidbody2D are static and don't move therefore mass is irrelevant and density is not used or at least it goes back to the default of 1.
Only colliders attached to a dynamic body use density.
I'm not even sure I follow what you're trying to do.
Im trying to do a little building game, where you create a vehicle from blocks, and then use it to clear levels. Everything works, but I have to re-set density for "block" objects in foreach loop. I wondered if there a "right" way to do it.