[Development] VR on the Cheap
Last update: 6-Jun-2016
Some time ago (actually almost 2 years!) I wrote a post [link] talking about making a DIY Oculus Rift after trying the DK1. As years gone by the Rift made it into DK2, which I also tried. The neat thing about DK2, besides the resolution upgrade, was the additional camera unit that you put on a stationary point (typically the top of your monitor), thus allowing translational movements with your head. Another interesting addition was collaboration with the Leap Motion that allowed you to see your hands in the VR world.
Some time ago (actually almost 2 years!) I wrote a post [link] talking about making a DIY Oculus Rift after trying the DK1. As years gone by the Rift made it into DK2, which I also tried. The neat thing about DK2, besides the resolution upgrade, was the additional camera unit that you put on a stationary point (typically the top of your monitor), thus allowing translational movements with your head. Another interesting addition was collaboration with the Leap Motion that allowed you to see your hands in the VR world.
This was a really cool concept, as HCI researchers will tell you without seeing one's hands or other representation of self, it's very dis-orienting. Plus head movements can only take you so far in interacting with the virtual world, both in terms of duration and accuracy. So adding hand representations with them being able to actually interact with stuff in the virtual world was definitely the right way to go.
Now we have the HTC Vive and the consumer version of the Rift. Both of these two VR contraptions feature an extra set of joysticks that work like controllers, with their spatial locations tracked along with the headset. What you get is a really immersive experience where you move in a 3D virtual space and do stuff with the controllers. I am really impressed.
But those are research equipment that I don't own. So what can I make that gives me the closest experience... with least amount of work?
The answer is Google Cardboard + a game controller.
Now we have the HTC Vive and the consumer version of the Rift. Both of these two VR contraptions feature an extra set of joysticks that work like controllers, with their spatial locations tracked along with the headset. What you get is a really immersive experience where you move in a 3D virtual space and do stuff with the controllers. I am really impressed.
But those are research equipment that I don't own. So what can I make that gives me the closest experience... with least amount of work?
The answer is Google Cardboard + a game controller.
Here are the things that makes the whole setup work:
Then the software side. It's easier than you think.
Now the development part. Surprisingly simple. Really, all you need to do is drag the GvrMain prefab under the GoogleVR>Prefabs folder to the scene. This will create all the necessary stuff you need, from the scripts creating a split camera view, to those that read the accelerometer data from your phone to rotate the camera view. If all you want is for yourself to look around, you are basically done. Just build and run and put the setup to your face.
In my case it was a bit more involved. I was making a flying robot controlled by the gamepad. In fact most of my time was just to map the controller keys/axes to the movements of the robot as a rigidbody in Unity. Anyone who has some experience in making games using gamepads would have done it better than me, as there was actually no difference in terms of scripting. But once I was done I just made the GvrMain prefab as a child of the robot, and when played it moved with the robot as if I was flying in it.
The only wrinkle I had was that the keys/axes mapping of the PS4 controller in Unity was different between PC and Android. So I had to make two bindings in order to be able to test the game in PC and play it on Android. Not a big deal, but something worth noting.
- The Google Cardboard ($5-$20). You can find it in Amazon, Ebay, or build it yourself. You can get some fancier versions made with plastic and padded with foam for greater comfort.
- The Nexus 5 phone ($150-??). Other phones should do, as long as they have a decent resolution and size (don't forget the VR app will split your screen in half), plus N5 is discontinued. The real issue here is its support for the controller. Someone suggested that starting from Android 4.4 PS4 gamepad was natively supported without rooting. But when I tried it on another phone (HTC One M7, Google Edition running Android 5.x), it did not work. On my N5 running Android 6.0.1 it worked on both Bluetooth and USB. But very quickly the Bluetooth connection exhibited signal drop and delay. Not sure if it's a hardware or software issue. So I switched to the never-stopped-working USB method. You can also find some other brand (e.g., Logitech).... can't verify though.
- OTG adapter and USB cable ($10+$10). The wired connection was the only way to go for me.
- PS4 controller ($40). As mentioned, you can use other brands. But I also use it for games on other platforms, so it's cheaper this way.
Then the software side. It's easier than you think.
- Unity 3D. My go-to game-making software because it is free and supports multiple platforms.
- Google Cardboard Unity package. The only extra thing you need is the package for the mobile platform that you are developing for [link]. It's about 300MB big so download it in advance if you want to make something quick.
- Driver for your Android device, or XCode for your iOS device. You should know these by now :)
Now the development part. Surprisingly simple. Really, all you need to do is drag the GvrMain prefab under the GoogleVR>Prefabs folder to the scene. This will create all the necessary stuff you need, from the scripts creating a split camera view, to those that read the accelerometer data from your phone to rotate the camera view. If all you want is for yourself to look around, you are basically done. Just build and run and put the setup to your face.
In my case it was a bit more involved. I was making a flying robot controlled by the gamepad. In fact most of my time was just to map the controller keys/axes to the movements of the robot as a rigidbody in Unity. Anyone who has some experience in making games using gamepads would have done it better than me, as there was actually no difference in terms of scripting. But once I was done I just made the GvrMain prefab as a child of the robot, and when played it moved with the robot as if I was flying in it.
The only wrinkle I had was that the keys/axes mapping of the PS4 controller in Unity was different between PC and Android. So I had to make two bindings in order to be able to test the game in PC and play it on Android. Not a big deal, but something worth noting.
Some useful tips in making a VR app on Android with Unity (ver5.3.0).
Overall I'm quite happy with this setup, especially with the amount of control I have using a gamepad. It really adds another level of immersiveness in the VR. The fact that Unity 3D is by itself a 3D game world development tool makes the process almost trivial. You can literally drag a prefab and make any 3D game into a VR game. There is of course some trade-offs in terms of resolution and processing power, but phones these days can do a lot of things, and they could only get better. As a quick demo, this is the way to go.
- The rotation animation will make the object disappear from the scene. It's a known issue in Unity, and to fix it, one has to go to the animation tab, right-click on the animation, and choose "Euler Angles (Quaternion Approximation)"
- The default image quality is really bad, try to set it to at least "Good" in the Quality Settings under Edit>Project Settings>Quality for Android (or the platform of your choice)
- The UI canvas (Screen Space - Overlay) does not work with the split screen script, so if you use any UI elements, they will actually be taking the entire screen instead of half
Overall I'm quite happy with this setup, especially with the amount of control I have using a gamepad. It really adds another level of immersiveness in the VR. The fact that Unity 3D is by itself a 3D game world development tool makes the process almost trivial. You can literally drag a prefab and make any 3D game into a VR game. There is of course some trade-offs in terms of resolution and processing power, but phones these days can do a lot of things, and they could only get better. As a quick demo, this is the way to go.