smallarrows.GIF
titlebar_image

Unity VR Open Close Animated Door, toggle animations

Scripts written for you by Alex Rickett, UCLA Game lab. These SteamVR scripts will open an animated door and reverse to close, useful for many events, such as turning on lights. This works with SteamVR.

In Maya
Animate a door opening and save to your Unity Assets folder.

Make sure the Pivot Center is located on the hinge point.


Download these script files: door_scripts.zip
Place the scripts into your Assets folder
     BackAndForthAnimation.cs and ClickEventsHelper.cs


In Unity:

Setup the Animation
Select your Maya Model in the Assets area

Switch to the Rig tab in the Inspector on the right.
     Change Animation Type to Legacy  (default was Generic)
     Hit Apply

Change to the Animation section of the Inspector tab
     Change the Clip Name to Take 001 + something descriptive

Hit Apply

(You may use either Legacy Animation or Default Animation.)



Setup the Model
Drag the animated model from your Assets to your Scene Hierarchy

Select the model in the Hierarchy
     In the Inspector, uncheck Play Automatically

Select the animated model in the Hierarchy

     Add Component->Physics->Box Collider      (Any collider will work.)

Drag the two scripts onto your model, one at a time.
     BackAndForthAnimation.cs
     ClickEventsHelper.cs



In the Inspector add the name of the Clip to the Back And Forth Animation script
     If the clip is from Maya you named it Take 001 + something descriptive.

In the Inspector, select the + to add an event to the Click Events Helper script
     Add the model to the box that reads None (Object)
    Change No Function to BackAndForthAnimation->ToggleOpen

unity_VR_door_script


Now run the game your door will open and close when you click on it.
This works with anything animated you want to start and stop.
You can assign other objects to toggle your animations such as a light switch and a light.


Add a Sound Effect
In the Inspector, select the + to add an event to the Click Events Helper script
     Add the model to the box that reads None (Object)
    Change No Function to AudioSource->Play ()
unity_open_door_audio


Probem Solving
If you have a mesh collider on the wall that has a door, you may need to play with turning on/off Convex.


door



smallarrows.GIF

© 1988-2022 34 years Jennifer Steinkamp