{"id":603,"date":"2016-12-23T19:45:31","date_gmt":"2016-12-24T03:45:31","guid":{"rendered":"https:\/\/jacksontech.net\/?p=603"},"modified":"2016-12-23T19:45:31","modified_gmt":"2016-12-24T03:45:31","slug":"vr-game-project-day-1-of-8","status":"publish","type":"post","link":"https:\/\/jacksontech.net\/index.php\/2016\/12\/vr-game-project-day-1-of-8\/","title":{"rendered":"VR Game Project &#8211; Day 1 of 8"},"content":{"rendered":"<p>Now that it&#8217;s winter break, I am going to sit down and do something I&#8217;ve been wanting to do for quite awhile: create my own VR game using Unity 3D and Google Cardboard. Thus, I am challenging myself to make a <strong>playable<\/strong> game (a short one) in eight days.<\/p>\n<p>The game is going to be a take on a &#8220;point and click&#8221; game, a-la the old 90s Lucas Arts adventures (like Beneath a Steel Sky). Except set in VR. Movement will be accomplished by &#8220;teleporting&#8221; (with a blink effect) to reduce VR nausea. The goal of the game is for you, a detective in a futuristic city, to gain access to a missing person&#8217;s apartment and find clues on their disappearance. This game is primarily a learning project, but I really want to produce something that people can actually play at the end.<\/p>\n<p>I spent most of the first day brushing up on Unity tutorials and updating my Android environment and Unity setup. At the end of the day, here&#8217;s what I accomplished:<\/p>\n<h1>1. Movement<\/h1>\n<p>Movement was the first hurdle. Some time ago, I had a simple game that used the Google Unity SDK&#8217;s IGVRGazeResponder interface to give certain GameObjects actions when the user looked at them and clicked the Cardboard&#8217;s button. Since then, Google seems to have made that interface defunct. The new way to do things is to hook into the event system. Here&#8217;s how I set up my project:<\/p>\n<ol>\n<li>Import the GVRViewerMain prefab from the SDK.<\/li>\n<li>Import the GVRReticulePointer prefab and make it a child of the camera.<\/li>\n<li>Add the GVRPointerPhysicsRaycaster Script Component to the camera.<\/li>\n<li>Add an EventSystem to an empty GameObject in my hierarchy, and add the GVRPointerInputModule Script Component to the same GameObject.<\/li>\n<li>For all the objects you want to be able to look at\/click:\n<ol>\n<li>Add some sort of Collider to the object, and mark it as a trigger.<\/li>\n<li>Write some <strong>public<\/strong> methods that will be your event handlers in a Script Component.<\/li>\n<li>Add some Event Triggers to the object. I used PointerClick. Make the Event Trigger call your event handler.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>A little more involved, but also relatively flexible. My movement script uses the <a href=\"http:\/\/wiki.unity3d.com\/index.php?title=FadeInOut\">FadeInOut script by KentyMan<\/a> at the Unity Wiki. Whenever the user clicks on a valid target for teleportation, the game fades quickly to black, repositions the camera, and then fades back in.<\/p>\n<div id=\"attachment_604\" class=\"wp-caption alignleft\" style=\"width: 768px\"><a href=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_movement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-604 size-medium_large\" src=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_movement-768x547.png\" width=\"768\" height=\"547\" srcset=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_movement-768x547.png 768w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_movement-300x214.png 300w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_movement-1024x730.png 1024w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_movement.png 1600w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><p class=\"wp-caption-text\">Very excite. Such game.<\/p><\/div>\n<h1>2. Basic World Design and Movable Scenery<\/h1>\n<p>I&#8217;ve had this idea in my head for awhile: a long balcony that overlooks a vibrant cityscape. Well, okay, right now the cityscape isn&#8217;t very vibrant. Okay, fine, I don&#8217;t have a cityscape at all. But I have a balcony, and that&#8217;s progress, so whatever.<\/p>\n<p>I designed the balcony in Blender and imported it into Unity. I am using no textures at the moment; right now, the emphasis is on geometry and sketching out the main areas for the gameplay. (It&#8217;s going to be really small.) If I have time, I will probably bake lighting in Blender and then either import as lightmaps or (if I can swing the low-poly aesthetic), bake the lightmaps to vertex colors and not use any textures at all. My phone will probably thank me for the latter. We&#8217;ll see!<\/p>\n<p>Last, I really wanted to get something moving, so I added sliding doors. I did this by calculating the target positions of each half of the door and then Lerp-ing between the start and end as a function of progress, calculated as (end movement time &#8211; start movement time) \/ duration. For extra fun, the Lerp-ing is nonlinear by using a smoothing function in place of a straight time parameter, so the door speeds up and slows down nicely.<\/p>\n<div id=\"attachment_605\" class=\"wp-caption alignleft\" style=\"width: 768px\"><a href=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_walkway.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium_large wp-image-605\" src=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_walkway-768x543.png\" alt=\"Picture of a walkway with green triangles as teleportation targets\" width=\"768\" height=\"543\" srcset=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_walkway-768x543.png 768w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_walkway-300x212.png 300w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_walkway-1024x725.png 1024w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/day1_walkway.png 1614w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><p class=\"wp-caption-text\">The green objects are teleportation targets.<\/p><\/div>\n<h1>3. Day 1 Results<\/h1>\n<p>Here&#8217;s the results of my labors running on my phone:<\/p>\n<div id=\"attachment_606\" class=\"wp-caption alignleft\" style=\"width: 768px\"><a href=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/Screenshot_20161223-192436.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium_large wp-image-606\" src=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/Screenshot_20161223-192436-768x432.jpg\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/Screenshot_20161223-192436-768x432.jpg 768w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/Screenshot_20161223-192436-300x169.jpg 300w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/Screenshot_20161223-192436-1024x576.jpg 1024w, https:\/\/jacksontech.net\/wp-content\/uploads\/2016\/12\/Screenshot_20161223-192436.jpg 1920w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><p class=\"wp-caption-text\">It looks much cooler with a headset.<\/p><\/div>\n<p>At the end of the project, I will make some or all of the project available for others to study.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that it&#8217;s winter break, I am going to sit down and do something I&#8217;ve been wanting to do for quite awhile: create my own VR game using Unity 3D and Google Cardboard. Thus, I am challenging myself to make a playable game (a short one) in eight days. The game is going to be &#8230; <a class=\"moretag\" href=\"https:\/\/jacksontech.net\/index.php\/2016\/12\/vr-game-project-day-1-of-8\/\">more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102,105,28,9,106],"tags":[110,108,109,107],"class_list":["post-603","post","type-post","status-publish","format-standard","hentry","category-game-dev","category-google-cardboard","category-personal","category-projects","category-vr","tag-eight-day-game-project-1","tag-google-cardboard","tag-unity","tag-vr"],"_links":{"self":[{"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/posts\/603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/comments?post=603"}],"version-history":[{"count":1,"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/posts\/603\/revisions"}],"predecessor-version":[{"id":607,"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/posts\/603\/revisions\/607"}],"wp:attachment":[{"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/media?parent=603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/categories?post=603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jacksontech.net\/index.php\/wp-json\/wp\/v2\/tags?post=603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}