Made With Unity | Unity VR Part 7: Doors In VR
Without creating coding, we can have a simple door on our VR environment with what we have learned so far using just Unity XR tools and other components.
We have a single door game object on our scene that hold the entire door asset, the frame and the door itself.
We find the “Door” object and we add the following components: Rigidbody, Mesh Collider with Convex checked and a Hinge Joint component.
The Hinge Joint will allows us to interact with our object around is rotation, by having Use Limits checked we can determined how far the door will swing. Adding the values from the images the door will swing forward movement from your hand, like opening your bedroom door; by inverting the Mix and Max values from the Limits you have swing the door with a backward movement.
If you press the Edit Angular Limits you can see a visual representation in where the object will rotate in order to make the swing effect.
Selecting the Door_1 object there are two empty game object that will represent the door Handle. The Handle object has the following components: Box Collider, Rigidbody and the XR Grab Interactable. Notice in the XR Grab Interactable where it says Movement Type is change to Velocity Tracking, by changing this the handle will not follow our hand when we interact with it.
Now we add the last component to our Handle object, Fixed Joint. Where it says Connected Body you will drag the object that has the Hinge Joint component, in this case is our Door_1 object.
We have the Sliding Door object; same has the Single Door, we are going to find the door object that is going to be our sliding door.
Our Sliding Door, named Cube_013_hinge, object has the following components:
Now we have another new component, Configurable Joint. Since the Hinge Joint only alters the rotation of a object, the Configurable Joint will allowed to customize a sliding behavior that we want for our door. Follow the setting showed on the image and this will allowed to slide our door. Now since the Linear Limit is the one that determines how far it will slide on both the positive X axis and on the negative X axis, we need to stop it so it dose not pass the door frame.
Has a child of the Sliding Door object, I have a empty game object named Holder that only has a collider and is only job is to stop the door when it reaches the end of the door frame.
Back to our Cube_013_hinge object I made a empty game object, Handle, to be the one that interacts with our VR player. The Handle has the same components as the door handle from our Single Door.
We just learn how to have two basic door in our VR environment: a Single Door and a Sliding Door.
BOTH DOOR ASSET ARE FROM FILEBASE