How To MAKE A VR GAME: Beginners guide to Virtual Reality & Unity XR Plugin

In AR/VR Development


How To MAKE A VR GAME: Beginners guide to Virtual Reality & Unity XR Plugin - read the full article about VR development, AR/VR Development and Augmented & Virtual Reality Solutions from Justin P Barnett - VR Game Dev on Qualified.One
alt

So you want to build a vr game? Well, you are in  the right place and more importantly youre doing this the right time. VR is at the precipice  of becoming a major platform. Weve just had two AAA video games made: Medal of Honor  and Half-Life and its just starting to get that momentum of becoming big.  So if youre starting this in 2021, I am excited for you and without further  ado lets jump into the tutorial. First thing we need to do is open up Unity.  This project is going to work for version 2020.1 or above. Were going to use 2020.2. Im going  to name this "VR_Tutorial". Let that spin up.

First thing Im going to do is go into scenes  and rename that to "XR_Rig_Template" so we can use this later, and we dont have to go through  this process over and over and over again. We just save one scene and then we can merge that  into other scenes that we need. Before we start adding things to the project we need to download  a lot of plugins and set a lot of settings, so Im gonna walk through all that and then afterwards  Im going to put a list on the screen. You guys just follow through with me and then you can pause  it and Ill show that list on the screen for you guys to just go through into your own projects and  check all the boxes make sure you got everything. First thing we need to do is go to: Edit > Project  Settings and were going to start down here at the bottom and work our way up. So, XR Plug-in  Management were going to install that. And then here youre presented a list of different VR  headsets that are available, but you notice that the HTC Vive isnt there, and the ones using  OpenVR arent in here. So were actually going to go install OpenXR now--it was OpenVR, thats  the old version and then OpenXR is the new one. And in order to do that were going to go up to:  "Package Manager" and "Enable Preview Packages", and I understand that these preview packages  do have bugs. Exit out of settings and now were going to go to window up at the top and  package manager and then swap this over to "Unity Registry" which shows us all of the packages that  we dont have yet--or all of the packages we do or dont have yet. Were going to scroll down until  we find the "OpenXR Plugin". Install that and one more we need to install is the "XR Interaction  Toolkit" down here at the bottom. Install that one as well. Now this interaction toolkit will  give us some samples, and were just going to grab this "Default Input Actions" and import that  as well. And that should be everything downloaded. Now if we go back to "Project Settings" and down  here in "XR Plugin Management" youll notice that there is an OpenXR and a features option as  well. So we can now select "OpenXR (Preview)" and then there will be this little exclamation  point that shows up. And it tells you that theres some settings that arent correct  for a VR environment or XR environment, so were just going to click "Fix All" and  your projects going to restart a couple times. After its restarted theres still going to be  an exclamation point and this is telling us that we dont have a profile enabled yet. And to do  that we go down to "Features" and then you select all of the controllers and profiles that you want  to market your game to. " have tried using Oculus in this, but for some reason theres this  giant like black screen up on the side, so I dont know whats up with that. So Im  just going to uncheck that go back to "XR Plugin Management" and select "Oculus". Thats  going to download the Oculus XR Plugin, but the rest of the video is going to be the same for  everyone. Thats the only like weird thing that Ive noticed for Oculus as of right now. I mean  its still--OpenXR is still in preview so theres still bugs and issues with it, so this could  be one of those that theyre working on fixing. Checking "Oculus" will download the this  Oculus settings part and I just leave all of these settings normal. Theres a few more  quality of life settings that we want to do, so were going to go up inside of "Project  Settings" still, go up to "Quality" and then this "Pixel Light Count" needs to be set to one (1) and  then were going to do "Per Texture": Textures and then "Anti-Aliasing" is going to go up to four  (4) and were going to uncheck "Soft Particles". This really helps optimize the project. And  then theres one more little settings type thing we need to do. Inside of "Preset  Manager" youll notice theres no presets in here yet, so were going to deal  with this. Exit out of "Project Settings" and then when we clicked the samples for "XR Interaction Toolkit" it put this in our project. So were actually going to click on each  one of these and add the "Action Based Continuous Turn Provider". Add the "Action Base  Controller Defaults". So if we double click on this guy youll see that it preloads all of the  different inputs that could be possible for any XR platform. So you got the head mounted display  position, rotation and then left hand you have all the different buttons for if you select so you  press the grip or if you move its the 2d axis or if you activate its the trigger pressed. And this  is for generic XR controllers, so this will work for Oculus, Vive, anything like that. But if you  wanted to add a extra button or something in here, you could add a binding and then you could click  "XR controller" and add a specific kind of input if you wanted to do that kind of thing. We  are not so, were going to delete that guy. Back to "Project Settings" and then inside  of "Preset Manager" there was nothing, and we added all of those defaults in here. And we  need to specify which controller for the filters, so we need to type "Right" in here and  then "Left" in this guy so they line up with the correct controller. Now  all the settings should be correct.

And we can start adding things into our  scene. First thing Im going to do is make an "Environment" game object. Add the directional  light into that. Add a 3d object plane, call that "Ground". Set all of these to  "Static". And now youre able to right click, and then inside of "XR" we can add a "Room Scale  XR Rig (Action Based)". Action based is the new input system. Device based is the old system that  theyre phasing out. I dont know how long theyre going to support that, but "Action Based" is what  we want to go for. So default is "XR Rig" and then inside of this XR rig you get a camera offset and  then you get a main camera, left hand controller, and a right hand controller. Theres one  thing that the preset XR rig doesnt have and thats a Component > "Input Action Manager".  So just search "input". Im going to add that in there, and then were going to add one (1) "Action  Asset" and the default input actions that we specified. Now your controller should be set  up, and if we hit play well see what happens.

So now youre able to move around. These little  laser pointers are connected to your hands and then you should be able to move your HMD  around and there we go. That is the basic setup. Congratulations, you have started a  project. Im going to show you two more things in this video. Im going to show  you how to pick up things, and Im going to show you how to move around the space. Those  are the arguably most important parts of VR, so lets get into that real quick. Picking things  up is super easy. So inside of our "Environment" were going to add a 3D Object > Cube. Move  this guy up a little bit. Press "R" and then size that up. Set him to "Static", and then  were going to add another 3D Object > Cube. Reset the transform on that. Press "W"  to get the position. Press "R" again. Scale this down to somewhere in the point  ones (0.1s) is always a decent size.

Move that so its right here on this  little table. So this is currently the default cube. In order for an object to be  grabbable by XR, we need to add a component. And then we can scroll down here to "XR" and then  were looking for the "XR Grab Interactable". And this will add a "Rigid Body" and it  will add a "XR Grab Interactable" component. Now you should be able to  pick it up, so lets try it.

Now when you point at the cube--its  not a good color--but you can see, if you point at the cube your laser pointer  turns white and if you press the grip, the cube will come to your grip and  then you can swap between hands.

And you can throw it too.

And its a distance grab--its a distance grab so anywhere your laser  touches you can reach out and get it.

Theres a few cool things you can you can play  around with inside of the "Grab Interactable". One is the "Throw Velocity Scale". So if you bump  this up you can throw objects super far, like just launch things. And then the "Attach Ease-in Time"  is how quickly it takes from when youre pointing at point at it and grab it to it actually being  in your hand. So you can create some pretty cool like low gravity almost effects by bumping that up  and then it just kind of slowly turns and rotates up into your hand which can be pretty cool. Feel  free to play around with those. Last thing were going to do is add a "Locomotion System". So  inside the "Hierarchy" Im going to right click, go to "XR", and then "Locomotion System".  And it presets your locomotion system to be teleportation and snap turns, but I dont  like teleportation as much. I think its just--it just feels gimmicky. Its not super fun. If  you can handle the motion sickness, and inside of your game theres a few things you can do to  counter the motion sickness of a continual move. A couple of those are: moving slow, so the slower  you move the better. Or being off the ground, so the higher you are off the ground when you  move the--. What causes the motion sickness is you see the ground going by you, but your bodys  not moving, so if you push the ground down you dont see the ground moving by you and your brain  doesnt think that its-- like it doesnt really get motion sick. So were going to remove the  "Teleportation" component and were going to add--. We can go down here to "XR" > "Locomotion"  > "Continuous Move Provider (Action Based)". And the locomotion system is itself. It  defaults with both controllers being able to do both actions which is going to get really  confusing, so we want to uncheck-- so we want snap turn to be on the right controller  move to be on the left controller. Im going to uncheck the appropriate  ones for those. And now when we hit play.

You should be able to move around. So  snap turn with your right controller theres a delay in there so you cant  just spam it. You can adjust the delay. And then you can also do a continuous move.

Now in order to use this XR rig in other  projects, I recommend saving it as a prefab. In order to do that Id take "XR Interaction  Manager", throw that into XR rig and your "Locomotion System". Put them both in the XR  rig and now you can save this as a prefab.

So inside of "Assets" we can create a folder  for "Prefabs". And then just drag this down into there, and now you have a setup XR rig prefab  that you can just drag and drop into any of your projects. And you have a setup movement system,  an action system and all that kind of stuff. So there you go. You see this face? This is the face  of pride. I am proud of you for finishing that project. In all seriousness, I am super excited  for you to be starting VR development. Its a crazy world and its gonna be amazing. I would  love to hear how this went for you. Please dont hesitate to add to the comments. If you run into  any issues or roadblocks please ask questions in the comments too. I personally will answer and  help you guys out, and if not me theres plenty of super smart people who watch this channel who  will also help you out. So dont hesitate to ask questions and jump in on the community. If this  video has brought you value in any way please dont hesitate to subscribe. It really gives me  the motivation to keep doing these videos. More VR tutorials are already in the works. Im already  working on some more stuff for you guys, and Im planning on doing some detailed step-by-step  walkthroughs of how to actually develop major games like Beat Saber or Super Hot VR and  basically just replicating-- doing several hour long videos about step-by-step how to replicate  these games. Just so you guys can learn. I learn by replicating. Thats kind of how my process  works, so I want to provide you guys with some of the same tools that I need in order to learn. If I  could watch a step-by-step guide about how to make Beat Saber or how to make Half-Life VR... That  would be amazing. So Im gonna provide you guys with some of that content. So subscribe for these  upcoming videos and Ill see you in the next one.

Justin P Barnett - VR Game Dev: How To MAKE A VR GAME: Beginners guide to Virtual Reality & Unity XR Plugin - AR/VR Development