How we implemented the door mechanics
Hand interaction is generally achieved through the SteamVR Interaction system. You can find the interaction system inside the SteamVR plugin for Unity:
We will soon publish another devlog entry to show you how we used it in Shopkeeper Simulator VR.
To move the door independently from the fridge, the door's mesh was separated from the fridge's mesh in Blender. The blender file was then imported into Unity. Here's the game object hierarchy:
The "Handle" object is the one which should react to the player's hand. Therefore, it was also separated from the door itself. The handle needs two components: The interactable component which is part of the interaction system and the script "OpenDoor" which is explained below:
The two methods
are specific to the SteamVR interaction system. They are called by the interaction system every frame the hand hovers over an interactable object (more on that in another post) and when the hovering ends respectively.
Basically, we are using the cross product of the force vector (pulling force of the hand) and the vector that points from the door's hinge to the transform where the hand is holding the handle (called "doorPivotToHand" vector). Together with the angle between the force vector and the "doorPivotToHand" vector, the angularVelocity is calculated and applied in FixedUpdate(). Note that FixedUpdate should be used and not Update, since we are changing a RigidBody's angular velocity.
Notice that in order to work, the door must have a Rigidbody and a Hinge Joint component to limit the door's angle. The HingeJoint's limits were set to 0 min and 90 max:
If you fund this useful, please leave a comment below. Also post any questions you might have. Thanks!