- Home /
Rotate door around pivot with physics
I want to rotate a door around its pivot with a hinge joint behavior. The thing is, and I know it's picky, I don't want to use Unity's hinge joint, because it slightly shifts the position of the object when rotating. Since the pivot is already set to the object's side, I was just wondering if there was a way to take advantage of that. Thanks.
This is just a thought. Haven’t tested this, but have you tried just putting a good old rigidbody with a box collider, setting the object origin to the center of the hinge and then freezing the unwanted rotations (likely the x and z axis) on the rigidbody and freezing the position completely??
I have, but it rotates around itself
you can do this through simple parenting. just add a rigidbody with only y rotation constrains unchecked. parent would be the hinge location and the door would be the child.
Ya, this would be better than having to modify the original model origin
I'll try that, but I don't see how it's any different from modifying the origin of the object.
You're correct, this is just adding an object you don't need in the middle if you have 3D authoring skills (Blender, $$anonymous$$aya, etc..), I would just change the origin of the object as I mentioned, but not everyone has 3d authoring knowledge
Answer by Acegikmo · Apr 29, 2020 at 08:32 AM
You can set its center of mass to its origin with
rigidbody.centerOfMass = Vector3.zero; // this is local space center of mass
Then freeze xyz translation and lock x and z rotation, and it should remain fixed and only be able to rotate around the Y axis
You might have to recalculate its inertia tensor though, in case the swinging looks and behaves wonky when hitting other objects though!
Your answer
![](https://koobas.hobune.stream/wayback/20220612232725im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Calculating Door Hinge Pivots 2 Answers
Adding child repositions parent tranform 1 Answer
Door Hinge joint glitches out when pushed to a limit? 1 Answer
Western door with Hinge Joint 3 Answers
How to make the door open after enter the password? 1 Answer