Lab4 : implement roll-a-ball in Virtual Reality

 Disclaimer : Labs and Lectures concern the course Human Computer Interface which I follow with my M2 "Virtual and Augmented Reality" at IPParis. 

This last laboratory, and yes it will concern roll-a-ball again... This time we will implement our application in Virtual Reality. I will use Oculus link on an Oculus Quest, a strong PC with a good graphic card, mine is a GTX1660Ti.

Setup

First step, you need to enable developer mode on your Quest and Oculus link. I haven't done this part (school material) but I found this tutorial if you need.

On this GitHub link you download VRTTK4, it's a Unity project which avoids a lot of issues during the creation of VR project. That the base of this project, let's open it in Unity. In Build Settings make sure it's Android for Oculus Quest (PC, for others). Then go to Unity's Asset Store and Download>Import Oculus Integration. All those steps could take a long time.

Awaiting download you could open our last project "Roll-a-ball" then go to Assets>Export Package. We export our previous game as a package. You can close this project because we go back to our VR project and import our  "Roll-a-ball.package" inside VRTK project. 

When you are done with all this you will see a lot of errors : we don't use UnityEngine.InputSystem in this project. Just comment the using and all the other line you need to comment will appeared.

Scene creation

Delete all environment of roll-a-ball's initial package. And create a VR scene (don't forget to put it in a group) : a huge floor : a table, our game and also move the UI :


To move the UI in the 3D space change the Render Mode to World Space, it will now act as a 3D object.

Oculus link

Start oculus link, and try to familiarize yourself with it. First and principal problem it's hard to switch between computer and helmet, attached a photo of me trying to use my PC and keeping the helmet :


Important note, with oculus link you can access desktop, you just need to know your keyboard by heart and you can work without removing your helmet.

Configure Roll-a-ball

This part will configure our roll-a-ball game in VR

  • Add a collider to roll-a-ball.
  • Use Layer on Roll-a-ball and another one on Player (the ball). In the Layer collision matrix have this : We want to move the boardgame without interacting or disturbing Player.
  • Mesh collider need to be a convex one and you don't need any script on our ground any more.

Configure our player

  • Add 2 prefabs : Project>Oculus>VR>Prefabs>OVRCameraRig. Tracking Origin Type Floor Level. Figure 1
  • Set references as we see in Figure 1. At this stage run your game to see if your scene isn't disproportionate. 
    Fig 1 : VRCameraRig
  • Add Project>Oculus>VR>Prefabs>OVRControllerPrefab as child of LeftHandAnchor and RightHandAnchor. Set Controller as respectively L Touch and R TouchFigure 2
    Fig 2 : OVRControllerPrefab
  • Add Project>Packages>VRTK Prefabs>CameraRig>TrackedAlias, Elements>Size =1 and drag OVRCameraRig into it. Figure 3
Fig 3 : trackedAlias

  • Add Project>Packages>VRTK Prefabs>Interactions>Interactors>Interactor as a child of LeftControllerAlias and RightControlerAliasFigure 4
Fig 4 : Interactor

  • Create an Empty GameObject name as LeftTriggerPressed. Add Components >Float To Boolean | Boolean Action. Add a new Event on Float To Boolean > Transformed. Drag Boolean Action to this event and select BooleanAction>Receive. Set Positive Bounds to 0.75 and 1. Figure 5
Fig 5 : LeftTriggerPressed

  • Create an Empty GameObject name as LeftTriggerAxis. Add Component>Unity Axis 1D Action. In Value Changed (Single), add a new event select Float To Boolean > DoTransform Drag and Drop LeftTriggerPressed,  In Project Settings > Input Manager > find VRTK_Axis9_LeftTrigger copy the value in Axis Name in the script. Figure 6
Fig 6 : leftTriggerAxis

  • Duplicate LeftTriggerPressed and LeftTriggerAxis and adapt it to RightTriggerPressed and RigtTriggerAxis

  • In Interactor (TrackedAlis>LeftControllerAlias), Drag and Drop ****TriggerPressed in Grab Action and ****ControllerAlias in Velocity TrackerFigure 4
  • Add this script to CenterEyeAnchor, LeftHandAnchor and RightHandAnchor, add references too. Figure 7 In OVRCameraRig linked alias in ****** Velocity. Figure 1
Fig 7 : Script in CenterEyeAnchor

Add Interactable to the scene

  • Drag Project>Packages>VRTK Prefabs > Interactions > Interactables > Interactable.Primary_Grab.Secondary_Swap
  • Disable DefaultMesh and replace it by the object you want to interact with. Figure 8
Fig 8 : Interactable

  • Important make sure to place the reference of Interactable.Primary_Grab.Secondary_Swap it's where your controller will appeared and your game's reference, here roll-a-ball. In this example you see the Interactable primary Grab is too high.

  • Other solution is to change the aspect of our controllers. A simple method to find them is to play your game and go back to scene mode : you can click on the object you want. Here I replace our controller by a little rectangle.


All the code is available on my GitHub.