Search Unity

Collider affects hinge joint

Discussion in 'Editor & General Support' started by adamjamescuz, Oct 29, 2012.

  1. adamjamescuz

    adamjamescuz

    Joined:
    Oct 29, 2012
    Posts:
    6
    Hi,

    I am making a chain of gameobjects using hinge joints, each gameobject needs to have a collider on it. If I set the 'isTrigger' property of the collider to true the chain acts exactly how I want, i.e nice an taught like a rubber band. With 'isTrigger' set off the chain is loose and saggy. I need to have the collider on it with 'isTrigger' set off so different chains can collide with each other - does anyone know why this is / a possible to solution to overcome this? It seems the collider is adding to each game objects mass or something.

    Many thanks
     
  2. QuantumRyan

    QuantumRyan

    Joined:
    Aug 30, 2011
    Posts:
    11
  3. fek

    fek

    Joined:
    Sep 14, 2015
    Posts:
    13
    I, too, feel obligated to bump this even though it's an older thread, because it took me forever to find, and it ended up being the answer to a problem I've been struggling with for months.

    I'll try to explain my bug, so it shows up better in search results for future users.

    I'm building a character editor, and many of the characters have tails. In their tails, I have a chain of rigidbodies connected via characterjoints. I wanted some of the characters to have tails that were loose and floppy, and others to have tails that were stiff and rigid. I attempted to do this by adjusting the swing limits and spring values, but no matter what values I used, I would encounter these problems:
    • The colliders would jitter, as if they were colliding with each other or some other colliders elsewhere in the character and then failing to resolve elegantly with projection. I thought that perhaps Physics.ignorelayercollision wasn't working, but when I traced out collision events, it confirmed that there really weren't any collisions happening.
    • No matter how high I set the spring values, I simply couldn't get the chain of rigidbodies to stay stiff / erect. The tail was always floppy, even with absurdly high spring values and extremely low swing limits.
    • When I changed the colliders to have .isTrigger = true, everything worked perfectly (except now there was no more collision, of course). But if I simply disabled the colliders, or even removed the collider components completely, it did not work as expected. It seemed that simply CREATING the colliders was all it took to ruin the tail physics, even if I consequently removed the colliders entirely.
    I was absolutely certain that there was some sort of collision bug happening somewhere, and just as I was getting exasperated, I stumbled upon this thread. I decided to trace out my Rigidbodies' .centerOfMass values to see if they were different when I toggled .isTrigger on and off, and sure enough, they were.

    The solution, for anyone else who finds themselves in a situation like mine, is extremely simple:

    You need to manually set every one of your Rigidbody components to have a .centerOfMass of [0,0,0]

    I made it the very first line of code after creating the Rigidbody, before I create or attach any colliders to it. Now, there is no noticable difference between the behavior of my character tails whether they're set to be triggers or not, except that collisions work properly.
     
    Last edited: Feb 19, 2017
    hkung and DavidErosa like this.
  4. fek

    fek

    Joined:
    Sep 14, 2015
    Posts:
    13
    After upgrading from Unity 5.2 to 5.4, the solution I explained above no longer works. I'm in the process of trying to find out why.

    Rage-inducing. It would be so nice if I could just add a collider to an object that's already behaving exactly how I want it, without it absolutely wrecking all of that object's behavior.
     
    GHOSTO00 likes this.
  5. fek

    fek

    Joined:
    Sep 14, 2015
    Posts:
    13
    Turns out there's yet another variable that gets automatically calculated when you add a Collider, and if you don't manually reset it back to your desired value, it screws up your physics.

    The variable is RigidBody.inertiaTensor, and it seems like the "default" value (or at least the one that works for me) is Vector3.One (1,1,1).
     
    GHOSTO00, hkung, Michcio174 and 3 others like this.
  6. DavidErosa

    DavidErosa

    Joined:
    Aug 30, 2012
    Posts:
    37
    On 5.5.0f3, @fek solution is still needed and valid... Thanks a lot!
     
  7. tavovallejo

    tavovallejo

    Joined:
    Nov 22, 2014
    Posts:
    13
    Small colliders also cause this problem, do what is said is this thread solves the problem
     
  8. Michcio174

    Michcio174

    Joined:
    Mar 14, 2015
    Posts:
    4
    Bumping this thread as it is hard to find but contains insanely useful information.

    I wanted to make a robotic arm in Unity 5.6 (a truck-mounted crane to be precise) using configurable joints. They were very wobbly. The crane consisted of several joints and parts. And even though all rotation axes except the desired one were locked, the parts were spinning a bit in locked directions as a result of drag and inertia. It was causing unrealistic vibrations at best and making the simulator look ridiculous and uncontrollable at worst. Finally I discovered that wide colliders helped somewhat, but they were not an option as crane would collide with other geometry in the scene.

    It turnus out that using RigidBody.inertiaTensor those joints can be stabilized even when no collider is attached to the joined rigidbodies. Just set it to some large values like (50,50,50). Thank you a lot, fek. I was having problems with that for weeks and I had no idea that parameter existed!
     
  9. CanadianGuy43

    CanadianGuy43

    Joined:
    Feb 3, 2013
    Posts:
    2
    This is still an issue as of Unity 2017.1.1.

    For those of you using Rigidbody2D, setup the rigidbody like so:
    Rigidbody2D.centerOfMass = Vector2.zero;
    Rigidbody2D.inertia = 1.0f;
     
  10. Ldnicon

    Ldnicon

    Joined:
    May 22, 2016
    Posts:
    3
    This is still an issue in Unity 2018.2.8f1

    Still working:
    Code (CSharp):
    1. rb.centerOfMass = new Vector3(0,0,0);
    2. rb.inertiaTensor = new Vector3(1, 1, 1);