- Home /
[VR] Door with Hinge Joint opens when hand moves in the wrong axis
Hi,
First of all, I should say that this is the first time I am doing something more complex than "just testing" with Hinge Joints, so it's possible I am missing some setting somewhere that automagically fixes the problem I am having here.
So, here is the problem I am having: I have a Hand object, controlled by a VR controller, which can interact with "Interactable" objects. I also have a door (I made a quick door prototype with basic geometry just to develop this functionality) which consists of a parent object, the door frame (scaled cube) and a door handle (cylinder). The handle is an "Interactable", and the parent object has a collision, Rigidbody, and Hinge Joint, which is set at the correct place, with the correct limits (I tested them out with the Motor function, and the door opens and closes within the limits, no problem). The problem arises when I interact with the door, and before I lay out any details, basically, instead of the door opening when I pull in my body's direction (door opens towards me), it opens when I move the hand towards the right. I'm confused. So here is how everything is laid out:
First, a video of the problem itself:
https://youtu.be/Rr-X1pjpi18
This is my Door GameObject:
This is my Door's (main parent GameObject) Components:
My Frame Components:
Handle Components:
And finally, Hand components:
How it works:
Basically, when the hand touches the Handle's trigger collision and the user presses the Trigger button on the controller, it will attach the door's Rigidbody to the hand's Fixed Joint, like so:
void Grab(IGrabbable grabbable)
{
if (!CanGrab || grabbable == null || grabbable.GetRigidbody() == null) return;
fixedJoint.connectedBody = grabbable.GetRigidbody();
}
So, the Handle (grabbable here) sends back the door's Rigidbody through GetRigidbody(). This is what I also use to grab objects and move them around, which works flawlessly.
Technically that is it. Nothing else is being done with the hand or the door until we let go of the Trigger button on the controller, which just calls a function called "Ungrab()" that sets the fixedJoint's connectedBody to null.
This is driving me a bit crazy, I managed to get it to work by turning doors into a special type of IGrabbable, that basically checks the position of the hand in FixedUpdate() and updates the door's rotation accordingly, but I feel like it's extra code that is not needed because I feel like the FixedJoint and HingeJoints should technically work. Why it's opening when I move to the right and not pull it away from its original position is beyond me.
I hope this was clear enough. If someone has any more questions I need to clear up please let me know. If you know what's going on here and a way to fix it, please, by all means, give me a hand over here (no pun intended, or maybe it was). Thank you for reading through this!
Answer by MikD · Oct 21, 2020 at 01:49 AM
I think this may be a case of the physics system doing its best to mirror your exact hand gesture while still following the limits you've set in the hinge joint. When you are attaching the hand to the door handle via the fixed joint, the handle is attempting to pull the door into position by matching not only the position of your hand but the rotation as well. A tried and true method is the one posted by a user named Valem on Youtube. He created a "fake" door handle (I refer to it as a "handle force") that is an invisible interactable that you can grab and move around independently of the door itself and then have the actual handle of the door, attached by a FixedJoint to your main door, use the physics engine to "follow" that "force". He used the MoveToPosition? command I believe. If you're making doors in Unity, the easiest method is to use the new XR system that can treat some interactables as velocity based check items. This means (from what I can see) that the object itself won't move but you can check how fast the item would have been pulled if you "could" grab it. You can use it to check for handles being pulled, wheels being turned, switches being flipped, whatever.
Answer by fotod1 · Dec 21, 2020 at 10:09 AM
Hi @Indemonai_Games , I am dealing with the exact same problem .Did you figure it out by any chance?
Your answer
![](https://koobas.hobune.stream/wayback/20220612204441im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SteamVR with VIVE : How can I drag object only Y transformation? 0 Answers
Hinge Joints ignore limits 0 Answers
Cube changes size when adding HingeJoint 2 Answers
My Fixed Joint springs back to Zero. 0 Answers
Doors and Hinge Joints 1 Answer