Unity + VR

From __space Wiki
Revision as of 12:11, 27 October 2017 by Steph (talk | contribs) (Miscellaneous)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page will be further updated when the Learn Unity First guide is finished, but for now, if you'd like to quickly get started with making a project using the Vive and Unity, these are some tips and a little bit about setting this kind of project up.

I’ve also compiled a playlist of videos about VR that are worth watching.

Getting Started: Edit>Project Settings> Player, which brings up something in the inspector, go to Other Settings and check off the Virtual Reality Supported box.

Use the plus icon to add OpenVR to the list of Virtual Reality SDKs (Doesn’t matter if Oculus is in that list or not). Window> Asset Store> search for SteamVR, download and import that plugin. Another plugin is VRTK, and while I will describe the use of the SteamVR Interaction System, which is what Valve’s “The Lab” uses, VRTK gives many more options and is our setup of choice. VRTK is in the Asset Store and depends on you already having imported the SteamVR plugin.

With any VR setup in Unity the first thing you want to do is delete the MainCamera object and replace it with a player rig.

There are many options for the player rig. SteamVR’s Interaction System has easily addable scripts for teleportation and picking things up and seems to be the newer and more official Steam/ Valve version. VRTK has many more options; less abstraction, something that can get confusing when using the Interaction System; and more documentation available for every method and class used.


Virtual Reality Toolkit (VRTK)

While there is a good amount of documentation for this plugin, it can seem a little overwhelming when first starting. This playlist does help, along with looking through and experimenting with the included example scenes. Aside from that, I’ve provided some tips for using VRTK.

(will add more to do with VRTK here)


Using the InteractionSystem rig

The player rig can be found (SteamVR > InteractionSystem > Core > Prefabs > Player).

First, I highly recommend reading through at least some of the pdf document included in the InteractionSystem folder to get to know some of the pieces to this system and what they can do. It also acts as a good reference for anything I don’t mention here and it gets updated along with the plugin. It would also be a good idea to take a look at the sample Interaction System scene to see many of the things you can do in action.

Teleportation

Add the [SteamVR > Teleport > Prefabs > Teleporting] object to your scene to get started. Now you have to say where user is able to teleport to by placing Teleportation Points around your map. You can also attach the [SteamVR > Teleport > Scripts > TeleportArea] script to any object to make the top plane of that object a legal teleportation surface. If you do apply TeleportArea to an object, either make a duplicate of it first and make sure it is slightly offset from the original so it can still be seen by the player as ground or an object.

Picking things up

Make sure the object you’d like to be able to pick up has a Rigid Body component with gravity enabled and then add Interactable and Throwable.

UI and Hints

The best way to add a new piece of UI visible to a VR user is to make a new canvas and change the Render Mode to World Space. You should also make the height and width much smaller when you do that (1 or 2 are good numbers for both, but do try to keep it below 10 if you need bigger UI elements). You can add a new text item to this canvas. After creating it, change the Anchor Presets to stretch both ways.

The scale should also be lowered (to less than 0.01) for the x, y, and z axes. I also recommend you add the Outline component to any UI text you may have. For buttons one must add the Interactable and UI Element scripts and then in the UI Element you can make it run any public function (and choose the parameters it sends too). For that to work you must also add a cube with a box collider so it can tell when the controller is in range to activate the button.

Just Using CameraRig

This is an alternative, but not the best method for most use cases.

Using Teleportation to Move

in the Hierarchy tab, go to the controller you would like to give the teleport ability to, and then in the Inspector tab, look for the Add Component button, and start typing in teleport, add the SteamVR-Teleport script. to be able to see where you’ll be teleporting also add the SteamVR-Laser Pointer script. Make sure to test before moving on.

Picking Up Objects (requires some coding)

I recommend using another tutorial, they explain it best.

For finding the distance between controllers, for scripting purposes, you can actually find the controller game object and get its transform.position. Then to get the distance (using C#) it would be:

Vector3.Distance(object1.transform.position, object2.transform.position)

You can use FixedJoints to attach any object to the controller, and then delete it on command.

Miscellaneous

Another very useful guide for unity +vive (I used it for ui stuff)

Small issues and the solutions I've found

On a certain update of unity (5.6) vive controllers stopped working. To fix, just drag the “SteamVR_UpdatePoses” script onto Camera (eye) [make sure it’s eye, not head]


Useful and or Interesting Articles