{"id":234,"date":"2023-01-31T02:24:00","date_gmt":"2023-01-31T08:24:00","guid":{"rendered":"https:\/\/www.armia.com\/blog\/?p=234"},"modified":"2023-01-31T02:24:00","modified_gmt":"2023-01-31T08:24:00","slug":"how-to-create-a-virtual-reality-app","status":"publish","type":"post","link":"https:\/\/www.armia.com\/blog\/how-to-create-a-virtual-reality-app\/","title":{"rendered":"How To Create A Mobile App With Virtual Reality?"},"content":{"rendered":"<p><a href=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/virthualreality-1-1.jpg\" data-rel=\"penci-gallery-image-content\" ><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-2666 aligncenter\" src=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/virthualreality-1-1.jpg\" alt=\"virtual reality\" width=\"501\" height=\"334\" srcset=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/virthualreality-1-1.jpg 501w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/virthualreality-1-1-300x200.jpg 300w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/virthualreality-1-1-330x220.jpg 330w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/a><br \/>\nA virtual reality app is a mobile app that uses the power of virtual reality to reach its goals. Virtual Reality is no longer confined to the world of Science Fiction and is more like science fact. Soon, the virtual reality market is expected to explode leaps and bounce by 2020 and hike more than $100 billion. Since the future relies on an immersive virtual world, there is no looking back.<\/p>\n<p><strong>1. Requisites for Creating a Virtual Reality App<\/strong><\/p>\n<p>We need an Oculus runtime 0.8 installed, along with Unity 5.3 or higher for Virtual Reality App development. The Oculus SDKs, samples, and asset packs are built to help you quickly and easily develop your VR app in your preferred development environment. We also require the below:<\/p>\n<p>&#8220;\u00a2 <strong>Hardware<\/strong>: Google cardboard<br \/>\n&#8220;\u00a2 <strong>Software<\/strong>: OS X<\/p>\n<p>At this time, it&#8217;s possible to develop on OSX 10.9+ with the Oculus 0.0.5 runtime, but as Oculus have paused development for OS X, we recommend Windows for native Virtual Reality functionality in Unity. The below components are compatible.<\/p>\n<p><strong>Windows:<\/strong> Windows 7, 8, 8.1, and Windows 10 are all compatible.<br \/>\n<strong>Android:<\/strong> Android OS Lollipop 5.1 or higher.<br \/>\nGraphics card drivers: Please ensure your drivers are up to date. Older drivers may not be supported. Please check the Oculus Configuration Utility to see if there are issues with your driver.<\/p>\n<p><strong>2<\/strong>. <strong>Process Flow of Creating your first Virtual Reality Project<\/strong><\/p>\n<p>Someone with an interest in Virtual Reality and coding can start with Unity. Unity is quite easy to pick up and can get your first project up and you can run it inside the same sitting that you install it in. Most people feel that the abundance Unity with respect to learning advanced graphics and networking is the reason that VR is so successful. They democratized game development so that anyone can program a game with ease. The following is the process flow of creating a virtual reality project.<\/p>\n<p><strong>Step 1:<\/strong> Create a new empty project from the Unity Home Screen which loads when you first launch Unity.<\/p>\n<p><strong>Step 2:<\/strong> Make sure that PC, Mac &amp; Linux Standalone is selected as the platform to use by visiting File &gt; Build Settings from the top menu.<\/p>\n<p><strong>Step 3:<\/strong> Create a new cube (Game Object &gt; 3D Object &gt; Cube) and position it in front of the default Main Camera in your new empty scene using the Translate tool.<\/p>\n<p><strong>Step 4:<\/strong> Save your scene (File &gt; Save Scene).<\/p>\n<p><strong>Step 5:<\/strong> Go to Edit &gt; Project Settings &gt; Player and check the box to enable &#8220;Virtual Reality Supported&#8221;.<\/p>\n<p><strong>Step 6:<\/strong> Enter Play mode by pressing Play at the top of the interface.<\/p>\n<p><a href=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/VR1.png\" data-rel=\"penci-gallery-image-content\" ><img decoding=\"async\" class=\"aligncenter size-large wp-image-293\" src=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/VR1-1024x464.png\" alt=\"\" width=\"1024\" height=\"464\" srcset=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/VR1-1024x464.png 1024w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/VR1-300x136.png 300w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/VR1-768x348.png 768w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/VR1.png 1295w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>During runtime, this can be toggled using the Virtual Reality Settings.enabled property as shown below:<br \/>\nusing UnityEngine;<br \/>\nusing UnityEngine.VR;<\/p>\n<p>public class ToggleVR: MonoBehaviour<br \/>\n{<br \/>\n\/\/Example of toggling VRSettings<br \/>\nprivate void Update ()<br \/>\n{<br \/>\n\/\/If V is pressed, toggle VRSettings.enabled<br \/>\nif (Input.GetKeyDown(KeyCode.V))<br \/>\n{<br \/>\nVRSettings.enabled = !VRSettings.enabled;<br \/>\nDebug.Log(&#8220;Changed VRSettings.enabled to:&#8221;+VRSettings.enabled);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p><strong>3. Camera Movement in Virtual Reality<\/strong><\/p>\n<p>We cannot move the VR Camera directly in Unity. If you wish to change the position and rotation, you&#8217;ll need to ensure that it is parented to another GameObject, and apply the changes to the parents Transform. Left and right eye cameras are not created by Unity.<a href=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/camera-movement.png\"><br \/>\n<img decoding=\"async\" class=\"wp-image-289 aligncenter\" src=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/camera-movement-1024x558.png\" alt=\"\" width=\"519\" height=\"283\" srcset=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/camera-movement-1024x558.png 1024w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/camera-movement-300x163.png 300w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/camera-movement-768x418.png 768w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/camera-movement.png 1109w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/a><\/p>\n<p>If you wish to get the positions of those nodes, you must use the InputTrackingclass.<br \/>\nusing UnityEngine;<br \/>\nusing UnityEngine.VR;<\/p>\n<p>public class UpdateEyeAnchors : MonoBehaviour<br \/>\n{<br \/>\nGameObject[] eyes = new GameObject[2];<br \/>\nstring[] eyeAnchorNames = { &#8220;LeftEyeAnchor&#8221;, &#8220;RightEyeAnchor&#8221; };<br \/>\nvoid Update()<br \/>\n{<br \/>\nfor (int i = 0; i &lt; 2; ++i)<br \/>\n{<br \/>\n\/\/ If the eye anchor is no longer a child of us, don&#8217;t use it<br \/>\nif (eyes[i] != null &amp;&amp; eyes[i].transform.parent != transform)<br \/>\n{<br \/>\neyes[i] = null;<br \/>\n}<\/p>\n<p>\/\/ If we don&#8217;t have an eye anchor, try to find one or create one<br \/>\nif (eyes[i] == null)<br \/>\n{<br \/>\nTransform t = transform.Find(eyeAnchorNames[i]);<br \/>\nif (t)<br \/>\neyes[i] = t.gameObject;<\/p>\n<p>if (eyes[i] == null)<br \/>\n{<br \/>\neyes[i] = new GameObject(eyeAnchorNames[i]);<br \/>\neyes[i].transform.parent = gameObject.transform;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Update the eye transform<br \/>\neyes[i].transform.localPosition = InputTracking.GetLocalPosition((VRNode)i);<br \/>\neyes[i].transform.localRotation = InputTracking.GetLocalRotation((VRNode)i);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p><strong>4. Render scale in Virtual Reality<\/strong><br \/>\nDepending on the complexity of your Virtual Reality scene and the hardware you&#8217;re running, you may want to alter the render scale. This controls the texel: pixel ratio before lens correction, meaning that we trade performance for sharpness.<br \/>\nusing UnityEngine;<br \/>\nusing System.Collections;<br \/>\nusing UnityEngine.VR;<\/p>\n<p>namespace VRStandardAssets.Examples<br \/>\n{<br \/>\npublic class ExampleRenderScale : MonoBehaviour<br \/>\n{<br \/>\n[SerializeField] private float m_RenderScale = 1f; \/\/The render scale. Higher numbers = better quality, but trades performance<\/p>\n<p>void Start ()<br \/>\n{<br \/>\nVRSettings.renderScale = m_RenderScale;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n&#8220;\u00a2 If we increase this to 1.5, you can see the asset looks much crisper.<br \/>\n&#8220;\u00a2 if we reduce the renderscale to 0.5, you can see it&#8217;s now much more pixelated:<\/p>\n<p><strong>5. Interactions in Virtual Reality<\/strong><\/p>\n<p>In Virtual Reality, we often need to activate an object that a user is looking at. For the Virtual Reality Samples, a simple, lightweight, extendable system allowing users to interact with objects. There are three main scripts:<\/p>\n<p>\u00e2\u2014\u008f <strong>VREyeRaycaster :<\/strong><\/p>\n<p>If a collider has been hit by the raycast, this script attempts to find a VRInteractiveItem component on the GameObject.<br \/>\nVRInteractiveItem interactible = hit.collider.GetComponent(); \/\/attempt to get the VRInteractiveItem on the hit object.<br \/>\nFrom this, we can determine whether the user is looking at an object, or has stopped looking at an object. If the user has started or stopped looking at an object, we can do something with it, such as call a method.<\/p>\n<p>\u00e2\u2014\u008f <strong>VRInput :<\/strong><\/p>\n<p>VRInput is a simple class that determines whether swipes, taps, or double-taps have occurred on the GearVR &#8211; or the equivalent controls setup for PC input when using a DK2.<br \/>\npublic event Action OnSwipe; \/\/ Called every frame passing in the swipe, including if there is no swipe.<br \/>\npublic event Action OnClick; \/\/ Called when Fire1 is released and it&#8217;s not a double click.<br \/>\npublic event Action OnDown; \/\/ Called when Fire1 is pressed.<br \/>\npublic event Action OnUp; \/\/ Called when Fire1 is released.<br \/>\npublic event Action OnDoubleClick; \/\/ Called when a double click is detected.<br \/>\npublic event Action OnCancel; \/\/ Called when Cancel is pressed.<\/p>\n<p>\u00e2\u2014\u008f <strong>VRInteractiveItem:<\/strong><\/p>\n<p>This is a component you can add to any GameObject that you would like the user to interact with in VR. It requires a collider on the object it is attached to.<br \/>\npublic event Action OnOver; \/\/ Called when the gaze moves over this object<br \/>\npublic event Action OnOut; \/\/ Called when the gaze leaves this object<br \/>\npublic event Action OnClick; \/\/ Called when click input is detected whilst the gaze is over this object.<br \/>\npublic event Action OnDoubleClick; \/\/ Called when double click input is detected whilst the gaze is over this object.<br \/>\npublic event Action OnUp; \/\/ Called when Fire1 is released whilst the gaze is over this object.<br \/>\npublic event Action OnDown; \/\/ Called when Fire1 is pressed whilst the gaze is over this object.<\/p>\n<p><strong>Deployment of Virtual Reality Project<\/strong><\/p>\n<p>One can easily test their project on the DK2 just by pressing play in Unity and you will have to deploy your project for testing outside of Unity and sometimes for distribution.<\/p>\n<p>When the deployment of Virtual Reality is done, one can consider the following:<\/p>\n<p>&#8220;\u00a2 Ensure that your scene(s) are included under the Scenes In Build<br \/>\n&#8220;\u00a2 Click Build and Run and Unity will export a standard Windows build with a .exe file and supporting content folders.<br \/>\n&#8220;\u00a2 Run the .exe file as usual, and if a project is built with VR support enabled, it will attempt to start in VR mode on the DK2 automatically.<br \/>\n&#8220;\u00a2 If you have issues with running the .exe, you may wish to optionally force VR mode, by using the command line argument -vrmode, which is covered in the VR Overview section of the Unity manual.<\/p>\n<p><strong>Use Case of Virtual Reality<\/strong><\/p>\n<p><a href=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/Header2.png\" data-rel=\"penci-gallery-image-content\" ><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-286\" src=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/Header2.png\" alt=\"\" width=\"1012\" height=\"500\" srcset=\"https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/Header2.png 1012w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/Header2-300x148.png 300w, https:\/\/www.armia.com\/blog\/wp-content\/uploads\/2017\/08\/Header2-768x379.png 768w\" sizes=\"(max-width: 1012px) 100vw, 1012px\" \/><\/a><\/p>\n<p>In this demo, the user has a visual experience in which he feels like he is walking through a&nbsp;landscape where some cubes are moving towards him. A white dot on the center of the screen represents the gaze input pointer. On targeting the gaze input pointer, the cubes will burst and disappear with in 3-4 seconds.<\/p>\n<p>If you want you can download the codebase for this sample app to test your concepts.<\/p>\n<p><!--HubSpot Call-to-Action Code --><span id=\"hs-cta-wrapper-6f015214-f875-4c6f-b5e0-800a1ad67bad\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-6f015214-f875-4c6f-b5e0-800a1ad67bad\" class=\"hs-cta-node hs-cta-6f015214-f875-4c6f-b5e0-800a1ad67bad\"><!-- [if lte IE 8]&gt;--><\/span><\/span><\/p>\n<p><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/6f015214-f875-4c6f-b5e0-800a1ad67bad\"><img decoding=\"async\" id=\"hs-cta-img-6f015214-f875-4c6f-b5e0-800a1ad67bad\" class=\"hs-cta-img aligncenter\" style=\"border-width: 0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/6f015214-f875-4c6f-b5e0-800a1ad67bad.png\" alt=\"Download VR App Code\"><\/a> hbspt.cta.load(2725694, &#8216;6f015214-f875-4c6f-b5e0-800a1ad67bad&#8217;, {});<\/p>\n<p><!-- end HubSpot Call-to-Action Code --><\/p>\n<p><strong>Conclusion<\/strong><br \/>\nIn the present scenario, along with the technology available to us, Visual Reality is all prepared for the development of auditory and visual immersion by specialist hardware like the Oculus. Although the Virtual reality headsets may only be few inches away in front of your eyes, it would seem like you&#8217;re looking at and is surrounded by a real environment. In the future, Virtual Reality will drive changes in OSs, GPUs, drivers, 3D engines, and apps, and ultimately enable a highly efficient Virtual Reality performance.<\/p>\n<p><!--HubSpot Call-to-Action Code --><span id=\"hs-cta-wrapper-59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2\" class=\"hs-cta-node hs-cta-59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2\"><!-- [if lte IE 8]&gt;--><\/span><\/span><\/p>\n<div id=\"hs-cta-ie-element\"><\/div>\n<p><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2\"><img loading=\"lazy\" decoding=\"async\" id=\"hs-cta-img-59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2\" class=\"hs-cta-img aligncenter\" style=\"border-width: 0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2.png\" alt=\"free consultation for mobile app\" width=\"669\" height=\"250\"><\/a> hbspt.cta.load(2725694, &#8217;59ae553e-9cc8-4c30-bb1d-57c0cc3c9fc2&#8242;, {}); <!-- end HubSpot Call-to-Action Code --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A virtual reality app is a mobile app that uses the power of virtual reality to reach its goals. Virtual Reality is no longer confined to the world of Science&hellip;<\/p>\n","protected":false},"author":1024,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/posts\/234"}],"collection":[{"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/users\/1024"}],"replies":[{"embeddable":true,"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/comments?post=234"}],"version-history":[{"count":1,"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":3112,"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/posts\/234\/revisions\/3112"}],"wp:attachment":[{"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/media?parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/categories?post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.armia.com\/blog\/wp-json\/wp\/v2\/tags?post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}