Search Unity

Colliders have mass?

Discussion in 'Editor & General Support' started by Ajaxamander, Aug 2, 2005.

  1. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    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?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    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.
     
  3. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    Yes, it does. My object hierarchy looks like this:

    Code (csharp):
    1.  
    2. +Dozer (contains control scripts for whole object, as well as rigidbody w/mass)
    3. |--->dozermesh (empty object with just a mesh renderer)
    4. |--->plow (just a collider)
    5. |--->shocks (rigidbodies/colliders/hinges, etc.)
    6. |--->wheels (rigidbodies/colliders/hinges, etc.)
    7.  
    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?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    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)

    Code (csharp):
    1.  
    2. rigidbody.centerOfMass = Vector3.zero;
    3.  
     
  5. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    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.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Yup. Center of mass can have some pretty big effect on the stability of the simulation.
     
  7. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    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)
     
  8. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    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.
     
  9. Ajaxamander

    Ajaxamander

    Joined:
    Jul 5, 2005
    Posts:
    36
    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()