HingeJoint violating limits and position when AddForce used

So in my project I have a CharacterController and I need it to push doors on hinge so I can walk through so I do:

void OnControllerColliderHit(ControllerColliderHit hit)
{
        hit.collider.attachedRigidbody.AddForce(hit.controller.velocity, ForceMode.VelocityChange);

Works OK except when the doors are at limit position and I push them with my CharacterC it is possible to break the limit at which point anything goes: not only is it possible to rotate doors beyond set limit but also to displace the hinge (and in term the doors) all together.

Seams strange but I can’t find anything on the subject on google. If you don’t have a solution to this particular problem then any suggestions on implementing such a thing differently are welcome.

Cheers.

A quote from some random guy:

So basically when there’s a large mass difference between the two rigidbodies you will have weakness problems like that. I’ve experienced that problem too but mess around with the masses and try making them equal and see if you can make it better.

Problem is that I’m using CharacterController. Thus no rigidbody, no mass. Also since in my code I set velocity directly the mass of character that does the pushing doesn’t matter.
I tried setting doors mass very high and very small but I cannot see any difference.

I was talking about the two rigidbodies that are required for the hinge - I haven’t tested it but try setting their masses to the be the same or switching which one is higher. I’ll try messing around with it in a bit and see if I can figure it out though, I have a project with a character controller and a door using a hinge that never violates the limits when I jump at it and add force.

In my case there is only one rigidbody for the joint so the joint “connects to the world”.

EDIT:

I tried connecting a piece of Kinematic geometry to the other end of joint and playing around with masses but still no noticeable difference.

I’ve done almost nothing involving Physics with unity. But a quick overview of Unity - Manual: Hinge Joint component reference will allow me to ask a couple of questions.

Have you set the value of use limits to true? Is the break force infinite?

Yes and yes. The joint doesn’t break but is rather pushed out of it’s position and when my character moves away it snaps back to it’s correct position. Similar for the limits.

Ohhhh I misunderstood the problem. What is happening is your door is may be pushed back by your player. You said your player had a character controller? Well the door’s rigidbody is smacking into your collider, the character controller, and since it’s not a rigidbody the door cannot exert a force to move your character and is thus stuck open or even over exerted.

That is my guess. How to fix it to preform the same function it does now I don’t know.

Sounds about right which tells me this is just how physics work internally and there isn’t much I can do about it. Seams strange though because it’s so basic. I would have thought people have discussed this problem many times before.

BUMP

I’ve done more testing and more googling and I’m really out of options.
This is so basics. Surely someone knows how to deal with this problem?

The only thing I can think of now is reducing the force your character is putting on the door - But I will let you know if I figure anything else out

I was using ForceMode.VelocityChange because I saw no reason to involve all the physics calculations. All I wanted is for the doors to move out of player way so matching it’s velocity with players velocity on collision sound to me like a solution.

To follow your advice I tried using ForceMode.Impulse with some small force. It’s better - it’s harder to violate joint restrictions but it’s still very much possible. I tried making the force very very small but then it takes for ever to push the doors out of character way and it’s still possible to mess up the joint.

Come on guys! this is so freaking basic! I cannot find anyone on Google raising this issue. Are you really telling me no one every needed to use CharacterController with HingeJoint? Really? I’m starting to suspect this is some kind of conspiracy aimed at me…

BUMP

is yours a shooter game. if so just have him blow the doors off. like in unity bootcamp i use the grenade. ;). try shooting the door. good luck :sunglasses:

Hi!

Firstly, do you have Use Spring enabled on the Hinge Joint? If that is true, the joint limit is soft and expected to be exceeded under great pressure.

Secondly, try increasing the Solver Iteration Count in the Physics Settings, if that doesn’t work, try Min Penetration For Penalty and decreasing the Fixed Timestep in Time Manager.

If those things still don’t help, use a PhysicMaterial on your door that has the absolute minimum friction and bounce.

If that doesn’t help either, you’re screwed :smile:

1 Like

No spring.

Tried all of it. Seams to be some little improvement but it’s still pretty easy to push joint out of its position.

I’m starting to think CharacterController is crap that should have been avoided in the first place? Probably not the only case where it causes problems in physics?

Any ideas on workaround? Perhaps some clever way to push CharacterController back when it’s getting too pushy?
HingeJoint class is sealed so no help on that front either.

I just remembered, you could try ConfigurableJoint, it has a thing called ProjectionMode . What it does is basically it makes sure the joint does not get too far from the constrained position which is what you need. It will take some patience to chew through the damn thing though to set the ConfigurableJoint up as a hinge joint.

And you are right, CharacterController is best to be avoided if you have an alternative, it is really slow among other things.

1 Like

The HingeJoint has that too so when I push the joint out of it’s position it snaps back when I move out of it’s way.

Here’s a workaround I found:
Add a Capsule Collider component to your Character Controller Game Object and set it’s values (Center, Radius etc.) same as they are in Character Controller component. It doesn’t do anything that Character Controller it self isn’t suppose to do already nevertheless it does solve the problem.

Your problem is caused by the fact that the character controller is not physics based, and hence causes trouble with the rigidbodies and hinges.