156 syllabus      site index      3D artists      past student work        DMA

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:
Place them in your Assets folder

In Unity:
Mac Big Sur OS BUG workaround
Download this 2019.4.17 scene, move the folder to your Desktop or working area.
This file is already setup with SteamVR and the SteamVR Emulator.
Rename the folder to a new project name.
Start the Unity Hub
     Select ADD
     Locate your renamed project folder
     Click on the project to start
Mac errors: Do not Move any files to the trash, answer preferably Open or Cancel a lot
Save the scene
Quit Unity
Mac: Open System Preferences->Security & Privacy
     Go to General tab
          Unlock the lock with your password
     Click Allow Anyway for any SteamVR apps listed, keep this running, there may be more files to fix.
Restart the Unity Hub
Open the project

Import SteamVR
SKIP this section if you used BIG SUR workaround, go to Setup the  Animation
Type SteamVR in the search bar of the Asset Store tab.
(Uncheck Longbow and Samples)


Add the SteamVR Player Prefab to your scene
Select the SteamVR folder from the Project tab
Select the arrow, open InteractionSystem, open Core, select Prefabs
Drag the Player into the Hierarchy tab

Delete the Main Camera
Select the Main Camera in the Hierarchy and choose Edit->Delete
The Main Camera does not work so well with this script.

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.

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 options
    Change No Function to BackAndForthAnimation->ToggleOpen


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.



© 1988-2021 Jennifer Steinkamp