How To Make A VR Game In Unity - Part One: Setup & Gun

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody today i'm going to teach you how to set up your xr interaction toolkit and how to make a basic gun now this is just going to help you get introduced to the idea of the xr interaction toolkit and how some of the things inside of it work as you can see i did try to record something similar already but i wasn't too happy with how listle i put into that tutorial so what i'm going to do is when we click new we're using 2020.2.1 f1 we're going to make a 3d project i'm going to call this vr gun now that unity is open we're going to go to window package manager i'm going to click at the top here and then unity registry click on this little cog advanced project settings and enable preview packages we're going to scroll down to the bottom and select excel interaction toolkit we're going to just hit install now that's installed we're going to click edit project settings excel plugin management and we're going to install xr plugin management now what we need to do is we're going to select oculus now if you want to build for oculus quest all you need to do is click this android and click obvious now that you have all of that installed we can right click over here click 3d object and plane this is just going to be our floor for our scene i'm going to make a quick material for this floor i'm going to name it floor and select the checkerboard or the albedo i'm going to set the tiling to 5x5 and i'm just going to generate my lighting once that's complete you can right click again click xr and you're going to want to choose room scale xr rig now most things in here are already set up for you what we're going to need to do is click on the main camera delete this tracked pose driver and enable this one here i'm not sure if this is just an issue i have but when using that tracked pose driver that comes with the xray it doesn't work so i just change it for myself now we're going to select both of the controllers i'm going to get rid of the interactors the line renderer and the ray interactor and i'm also going to get rid of the xr controller and add in the excel controller which says device based and you're going to need to change the controller node from right hand to left hand on just the left hand now i'm going to set up something for later on which will be the grabbing so if you don't want to grab objects in your game for whatever reason you can skip this part so we're going to add an xr direct interactor and a sphere collider we're going to set the radius to 0.25 and set it to its trigger that is the xlr rig setup if you wanted to you could load up the game and you would have an ex art rig i'm going to now teach you how to create hands and how to do the gun so if you don't need if you don't need hands for your game or if you don't need a gun for your game or anything like that you can skip this whole section you are done so what i use for my hands is this package created by valon he's a brilliant vr developer youtuber and he's where i learn most of the basics for vr myself so i'm just going to drag this into our scene i'm going to be honest this is the only thing i've ever had to use for my hands it's just perfect there is just one thing that i like to change which is in the models oculus and materials and i personally like to make it opaque and you can mess about with the color i'll make mine a dark gray for example and you can go into your prefabs drag the left hand under the left hand controller and the right hand presence under the right hand corner now if you load up the game it by just clicking the play button make sure you have your headset plugged into your computer you should see your hands in game so i'm just going to come up here and click play and here you go we have our hands and they have some nice animations on them if you press your trigger your pinch if you press your grip button you will grip quite easy quite simple but works very effectively if you'd like to know how this works you can go into the hand presence script i do recommend looking through it next i'm going to teach you how to make your gun so to start off i'm just going to make the bullet so we're going to make a capsule we'll bring it up zero zero zero and i'll probably make the point one on all the scales now if you have a model that you'd like to use for yours you can i'm also going to create another material this is just going to be red for the bullet and you can rename it but make sure that you have it set to zero zero zero on your position now we can drag it into our prefabs folder and you can just delete this from the scene next up i'm going to make a really basic gun model by just putting two cubes on top of each other so if we go 0.25.25 and 0.5 on the scale this might be too big but we can judge that when we actually get into the game i'm going to make this 0.5 on the x and 0.25 on the others and this is just a very basic gun model that i'm going to use we can make another material i'm just going to call this gun i'm going to make it a nice metallic black now there probably is a bit of z fighting you can just lower this or increase it by like point zero zero one and the z fighting should have stopped as you can see here you're gonna want to create an empty and name it gun and drag your two cubes inside reset this position to 0.00 and you're probably going to want to drag your gun over to 0 000 as well which is the center i messed up there you don't really have to put your gun at zero zero zero you can just put it in the scene on top of what i'm going to make as a little table for the sake of grabbing it i'm just going to rotate it on its side by 90 degrees and i'm going to pop it just on top of this table here now i do think this is a bit big so i'm going to decrease the size next you're going to want to add a box collider and a rigid body personally i set interplay to interplay it smooths out the movement and stops it being jittery sometimes and we're going to multiply an xr grab interactable now here you can mess about with some of these and it's a good way to learn how it works it's just mess about with it you don't need to um worry about it saving or not because if you want to reset all of this you can just right click and reset so mess about with the velocity and and smoothing and see what these different movement types do velocity tracking i believe makes it so you can interact with the environment and stuff that might be fun to mess about with make sure that when you get back to following tutorial you right click and reset if you do want to test you can now go into the game oh ah something small that seems to have happened with my collider is it's messed up so i'm just going to adjust this instead of adjusting that glider what i'm actually going to do is i'm going to open up this little section here and i'm going to make two colliders now this basically means that i can drag in the two colliders from these game objects here and they will be used as the clyde of this gun so now if we click play and enter the game you will see that we can kind of grab the gun now there is a few issues which i'm going to sort out now the cubes are we're going to actually reset this position zero zero zero and then we'll reset this position to zero zero zero and zero zero now this is going to mess up the gun model as you can see so i'm going to just take this top cube here i'm going to replace it to roughly where it was and now you can grab this and this the gun should look normal when it's at zero zero zero or it shouldn't be off in the distance so make sure that it looks somewhat normal when it's here now i'm gonna move this back to where it was sorry if that was a bit hard to understand hopefully you got the the gist of it and we can now properly grow our gun the only issue is the rotation which i'm going to show you how to make look good now what we're going to want to do is right click our gun and create an empty we'll call this the grab point now how this works is as you can see blue means forward so wherever blue is facing is the forward direction of your gun so i'm going to rotate this by negative 90 degrees for mine it might be different for yours and we want to grab around this area and if you now click on the gun and scroll down you will see this area called attach transform if you drag your grab point into there and load up your game you will see we now grab our gun properly now there is one more thing which you can do personally i'm not a big fan of this i like having my hands but if you would like to hide your hands when you grab objects you can select both of your controllers here and select hide controller on select make sure that's true now when you're in great game and you grab an object i believe that's because we don't have the model prefab created so if we drag our left hand presence into our model prefab same with our right hand presence ah wait sorry that that's wrong that's me my bad there go into prefabs and now drag right hand presence into the left hand presence into hip now when you click play you'll see you still have your hands but your hands now hide when you grab your object finally i'm going to teach you how to actually make the gun work so i'm going to add a script to the gun and call it gun once this is open you can just hello future my commentary here was not great so just copy from the screen so what we're going to want to do is we're going to want to instantiate bullet prefab we're going to want to do that at a position so if we go back to unity i'm going to want to create a new empty shoot point and put this at the barrel of your gun or at the end of the barrel of your gun now here we're just going to put a comma and do shoot point and we're going to watch spawn this at shoe point dot transform i forgot you're actually going to want to serialize these fields or make them public either one works if you remember we created a bullet prefab if you drag that into here and you drag the shoe point over here that should be good so we're going to go back to our script i'm going to say change shoot point dot transform to shoot point dot transform block position and then quaternion dot identity hello future rigged again basically what i forgot to show you here is that you need to click on your gun and you click on activate and drag your gun script in here and select your whatever you named your um method so i named mine shoot in the video as you can see here is public which you make sure it's public and remember the name if you now go into the game and press your trigger while holding the gun you should see the bullets appear so if you enjoyed today's tutorial and you want more make sure you click subscribe i will be doing more tutorials like this over the next few days if you need anything cleared up just leave it in the comments and i will try to get back to you as soon as possible and if you have anything in specific that you want to learn maybe vr movement which i have planned so don't bother asking for that but feel free to ask in the comments you
Info
Channel: RiggedDev
Views: 421
Rating: undefined out of 5
Keywords: unity, vr tutorial unity, vr in unity, how to make a virtual reality game in unity, vr unity, oculus tutorial unity, virtual reality unity tutorial, unity vr, oculus quest unity, vr for unity, how to make a vr game in unity, unity xr toolkit, xr tutorial unity, unity vr tutorial, unity 3d, unity tutorial, xr unity tutorial, unity xr toolkit tutorial, unity 2020 vr tutorial, unity xr, vr unity tutorial, unity vr development, vr development unity, unity vr game
Id: EjKvB9YQQY8
Channel Id: undefined
Length: 13min 8sec (788 seconds)
Published: Thu May 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.