Collider affects hinge joint

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

I know this is an older thread, but I had the same problem and I think I know why. If you don’t set the center of mass from a script it will be calculated automatically from all colliders attached to the rigidbody. So if your joints use anchor offsets, the center of mass will be offset from the origin.

1 Like

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.

10 Likes

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.

4 Likes

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).

11 Likes

On 5.5.0f3, @fek solution is still needed and valid… Thanks a lot!

1 Like

Small colliders also cause this problem, do what is said is this thread solves the problem

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!

1 Like

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;

This is still an issue in Unity 2018.2.8f1

Still working:

rb.centerOfMass = new Vector3(0,0,0);
rb.inertiaTensor = new Vector3(1, 1, 1);
1 Like

Confirmed bug still exists in 2019.3.1f6, confirmed this solution still solves the issue. Can’t believe for 7 years devs have been hacking at this, all to put a collider on a hinge joint. What a sin! Unity should update their docs with this as a suggestion, or at least caution about the potential problem

Still doesn’t work as of 8/16/2020 - tried the code work around above and that doesn’t work either.

Gonna add onto the pile of people experiencing this issue.

Was having trouble while simulating tank tracks using hinge joints as they would end up jittering all over the place once more of the links were being moved, thankfully fek’s solution worked for me in 2021.1.15f1