It seems like when I add an empty GameObject to the hierarchy, then I add a “Collider” component to it, the object has a mass. Even though it doesn’t have a RigidBody componenent, it still falls to the ground.
In the case of my more complicated primary game actor (a vehicle with wheels) when the collider comes into contact with the ground, it causes instability in the physics system, and everything kind of “wigs out.”
Has anyone else noticed colliders acting as if they have mass (or weight as the case may be)? Is this a bug, or have I screwed something up as usual?
Possibly one of the parents of the collider contains a rigid body?
If you have a rigid body with transform children and the transform children contain colliders, they will be added to the rigid body.
This is how you create compound colliders.
Yes, it does. My object hierarchy looks like this:
+Dozer (contains control scripts for whole object, as well as rigidbody w/mass)
|--->dozermesh (empty object with just a mesh renderer)
|--->plow (just a collider)
|--->shocks (rigidbodies/colliders/hinges, etc.)
|--->wheels (rigidbodies/colliders/hinges, etc.)
Is this non-optimal? Should I be doing it differently?
Okay, the compound colliders thing makes some sense, but shouldn’t the center of mass still be based entirely on where the rigidbody is, and not where any parts of the compound collider happen to be?
I think your setup is perfectly fine.
I tend to think that in 99% of the cases, having the center of mass be calculated automatically by all colliders is the right thing.
For the other 1% you use:
rigidbody.centerOfMass
And if you want control over all of it:
rigidbody.inertiaTensorRotation
rigidbody.inertiaTensor
You should setup the rigid bodies mass properties inside the Start () function in C# or outside any function in javascript. (Which is the same as having inside the Start function)
rigidbody.centerOfMass = Vector3.zero;
Aaaah, clever. I can see that ‘averaging’ the colliders being useful in the future. It just so happened that as I was working through constructing my dozer, it started ‘breaking,’ and I was very confused. I’m still confused about why the new collider coming in contact with the ground is thrashing the physics system, but maybe that will clear up after I fix this center-of-mass thing.
Yup. Center of mass can have some pretty big effect on the stability of the simulation.
Would it be more appropriate to put that mass-centering call in “Awake” or “Start” in my C# script? (Is one depricated, or called before/after system calls or something)
Put it inside Start for now.
There is a bug which makes the Awake function sometimes be called before other objects are initialized. This will be fixed with 1.1.
The difference between Start and Awake in general is:
Awake is called when the scene is loaded.
Start is called just before the first update function is called.
This way, when the Behaviour is disabled, you will only get the start call when the Behaviour becomes enabled.
Fabulous! Thanks for the help. Resetting the center of mass seemed to fix everything. Plus it’s good to know the subtleties between Awake() and Start()