How to make a virtual reality app

It is easier than you think!

Bernardino Rosa
Haptical

--

Virtual Reality is exciting, it’s fun…it’s great!…well that’s what other people were saying, but I never experience it, so I couldn’t have an opinion.

Until I said enough is enough, let’s jump to the hype train.

I bought a pair of glasses for smartphones, saw some 360º youtube videos and some mobile App games and I was like…

The experience was great, so I had to do my own VR app.
These were my steps:

1.Idea

First, I needed an idea! There are plenty of apps that we can build to explore VR, I had to make something fast but useful, so I did a Beer Museum :P

2.The Tools

3.Let’s Start

Setting Up Unity for Android VR App

With a new project in Unity, go to Assets and import the Google SDK previously downloaded.

Then go to File->Build Settings ->Select Android then click on Switch Platform.

After the switch, go to Player Settings ->Other Settings tab, set the following configuration:

Chose your Package Name also, it must be unique.

Making the 3D Model

I use blender to make the museum, just did a google search for museum pictures, search the information that I needed for the art paintings and it was done!

As I said before, I could have downloaded some 3D museums models or an interior of a house, what is important is having a model where we have space to walk on.

Making the Camera Move

Delete the MainCamera from the scene and drag and drop the Google camera, which can be found in Assets ->GoogleVR ->Legacy ->PreFabs -> GvRMain.

In recent versions of the Google VR SDK we can use GvrEditorEmulator for the Camera.

Add a capsule collider to the camera:

Add a Rigid Body:

After that, create a script for the camera movement, with the camera selected go to Add component, search for “script”, click on New Script and name it “character” :

Find the script in the Assets folder, double-click and enter the following code:

using System.Collections;using System.Collections.Generic;using UnityEngine;public class character : MonoBehaviour {public Transform vrCamera;public float toogleAngle = 30.0f;private bool walking =true;private Vector3 initPoint;// Use this for initializationvoid Start () {  //Get the start point  initPoint = transform.position;}// Walk when looking Downvoid Update () {   if (walking) {       transform.position = transform.position +  Camera.main.transform.forward * .5f * Time.deltaTime;}if(transform.position.y < -10f){  transform.position = initPoint;}if (vrCamera.eulerAngles.x >= toogleAngle && vrCamera.eulerAngles.x <= 90.0f) { walking = true;} else {  walking = false;    } }}

This code will only move the camera when you look down, you can configure the angle threshold with the variable toogleAngle.

In the rigth side of the screen expand the GvrMain -> Head -> Main Camera, then drag and drop to the Vr Camera variable in the script:

Importing the Model

Create a plane, this will be the floor:

Import the model, go to Assets-> right click -> Import new Asset-> Select your model

Click on the model and activate Generate Colliders and click Apply, this way the camera will not pass through the walls of the model.

Drag and Drop the model to the scene, press play and it’s done!

Mac: option key + move the mouse | Windows: alt key +move mouse

You can add textures to the model, a skybox for the environment and lighting of the scene, the possibilities are endless….

You can check my final work in Google Play Store ->Beer Museum<-

Museum Entrance

That was my first Mobile VR App, I know I have plenty of room to improve the app…but it already give me a glimpse of the possibilities in this technology, today a simple App, tomorrow the conquer of the world, who knows :P

Tweet me on @_nzMedia_ or leave a comment.

Like Beer?! Check out BeerStylist on Google Play Store ;)

If you like this article, please press 💚 :)

READ MORE ON HAPTICAL

Follow us on Medium to get the latest Virtual Reality trends and news in your inbox every week.

Sign up to our exclusive reports today! Discover how Virtual and Augmented Reality are transforming your business.

--

--