How to Setup a VR Game in Unity - VR Rig & Animated Hands!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on fellow game developers my name is Muddy wolf and in this tutorial I'm going to show you how you can set up a VR game like you're seeing on screen in unity we've set up hands we can actually use now there's a shout out to failures tutorials for this hand asset I will leave the link down below to download these hands to use and we'll be setting up the XR interaction toolkit to actually use in a VR world and you'll be getting started making your first VR game in no time so without further Ado let's get in to the code so let's first start off by creating a new Unity project I'm going to be using 20 21.3.11 F1 uh it's an LTS version so it's going to be scored for a while um but anyway let me show you how to get set up so we're just going to say VR setup here click create and that's going to create us a new project so I'll see you once that is ready the first thing I'm going to do is just add a ground plane for our selling for our player to stand on just call this ground you can name whatever you want scale it up and there we go I'm just going to reset transform so it's at zero zero which is down here and we can add a material so let's just right click create a material this is optional again you can create material if you want to we'll just call this the ground and we'll set this to a darker gray it's not too not I don't write that great let's go die let's create a dark because I think like that there you go now you can see that it is a dark blue obviously if I don't know if I showed you dropping that on there but that's now on there now we've got our ground we can actually get started with setting up the rest of our project so what we want to do is we want to install the XR plugging management tool by going to edit project settings and go down to XR plugin management now we can click install XR plugin management here and this will install all the uh packages and stuff we need to get started with VR development now what we want to do is we can select providers for each platform and the provider I'm going to go for open XR where is basic arrow for this it has support for the most amounts of VR headsets um and same on Android here the this project is using new imposition but the native platform back ends for the new emphasis of the night over there just means to know that they've come through do you want to to enable the back ends doing so restart the editor uh no this is fine we can leave it assist for now let that load you can restart if we need to in the future so then we also want to go to the um Android tab here and I'm going to select open XR as well click I'm just going to click fix all okay that's restarted so now that's done you can see it's giving us a little warning here on both the XR and the actual screen that's because we need to set up the actual interaction profiles currently we haven't set any so what we want to do is go to our interaction profiles and actually add each and every one of these profiles uh I'll just go through and add everyone this will give you the maximum support for all the interaction profiles then I'm going to go over to Android and just add in the actual Oculus touch controller because we're not going to be using any of these other ones on me or because unless you need them then feel free to add them but we only need the Optimus ones for this once we've selected all the all the uh profiles interaction profiles so you can go back to the XR plugin management and actually see that warning has now gone from both of these areas so what I'm going to do is go into package manager and go into Unity registry and search for XR interaction talk okay and as you can see here we have the interaction toolkit here click install so now that's done we can actually go into samples and one thing we're going to want is the starter assets because these have stuff we'll want to use later on just click import and then that should add them down here where we can use them later on this actually adds in input actions for our controllers and we can actually use these later so now we have the XR interaction toolkit what we want to do is remove the actual main camera because this is no longer needed and we actually want to go down to XR go down to XR origin and Implement one of these now I'm just going to reset its transform to the center and another thing we want to do is we're going to change its tracking origin to floor if we set to floor this will take into account the actual players height and you'll be the actual height of the ground as you are in real life now once we have the main camera we can actually start up our Oculus and see this moving around inside now to actually try this out you're going to need to be using you need to have a VR headset connected to your PC and on which is able to use the editor now I am actually using the Oculus Quest or The Meta Quest 2 and I'm going to be using air link to link it to the Oculus Quest app on the Windows PC which will then allow me to hit play on Unity to actually test out the okay so what we're going to do is I'm just going to hit play and we should be able to see my me moving inside of VR and there you go I'm actually able to look around you can see we're able to move around look all the way around the environment up down to the floor to the sky and you can see that's now all working inside of the Oculus Quest there's quite a few things that's missing and that is the hat so we actually want to set up a bunch of different things so inside of the camera offset we are going to want to create some hands so I'm going to create an empty object in here called this left hand I'm actually going to add the XR controller action base to this script and then we're going to want to duplicate this and just call this the right hand right hand like that so let's actually go up here and select a pre-fret set for the left hand so what we're going to do is Select this and you can actually see if we bring this out and sell it to this you can see xrd default left controller so we can set the left preset to the left hand and we want to do the same for the right hand to set the preset and that's going to set it all up for us we don't have to do anything for this we then actually want to go back to the XR origin and add a we want to add in the input action manager to our XR origin and we're going to want to also drop in our action so if we go down to our star kit so you can see we have an xri default input action we can drag and drop these and that will set up our profile for us now we can just quickly to test this add in oh not a parent right click on both the hand and the right hand and just add in a severe collider for both we can select these and Shrink them down um I'm probably going to say thank like 0.1 make them quite small let's have a look that should be good enough and then if we actually test this out by hitting clay and putting on our VR headset now have two hands two balls as our hands you can see we can move these around I can hit them to gaffle the controllers and you can actually see these balls floating around following where my hand position is but balls aren't that exciting for for your hands so how can we make this better well we can actually use oculus's um models hand models and actually import them here so we actually have some proper hand models so let's just delete both rows so once you've downloaded the package this is actually a package from Salem tutorials or phylum and he has created an awesome package which basically has hands and net models and the animations for those hands inside of this package so what we can do is just drag this into our game if we move this over we can actually drag it in here drop it in here and it will ask just to install it there we go and you can see here there's a bunch of different things we've got animations for the hands along with animated controllers models and the prefabs for all of this so now if we just hit import this will import all of this into the game and what we can do is go under our left hand we can drop in the left hand prefab and under the right hand we can drop in the prefab too now you can see they're actually pink now phalem in he actually has a similar tutorial to this but he actually uses urp so that's why these are pink I'll leave a link down below to his tutorial channel so you can actually check out his side of things as well if you want to he goes into a lot more depth and here you go so you've got the left hand and the right hand but the material doesn't work right so if we just drop these down and we actually select the material here we can basically change the Shader to go to standard and there you go you can see that thing system from being pink if we also go to the material it's actually here we can change the color of these we can mess around with all the settings um to change them and I think I'm going to have our hands as a nice purpley color pinky purple let's go for more pink sounds like that let's make it less harsh and there you go some pink hands to be in our world so if we actually hit play and put our headset back on you'll see you now have hands inside a Fiat now you can't actually press the buttons to grip or detract these yet but we'll add that in a second so now you have hands for your game so to finish this off what we need to do is actually animate our hands um we want to add animators to our hands and actually use them so what we want to do is I'm just going to select both hands I'm going to add a component and call this the hand animator the hand animator controller which will control our hands once the scripts compile what we can do is open this up inside of any text editor I'm going to be using visual studio code so inside of our script the first thing we want to do is say using Unity engine dot input system because we're going to be using the new input system to actually use this we then want to set up two different input actions now I'm going to serialize these and create private input Action Properties and call this the I'm going to call this one the input Trigger action and we will also have one more private input action property which will be called the inputs or just you know what we could just call this the Trigger action and we'll also call this the rip action and then under here we want to get a reference to our animator so we'll say animator anime and then in the update function we want to actually get two floats I'm going to create a float here and we'll call this the trigger value and this will be equal to our our Trigger action dot action dot read value and then we want to tell it what type of value we want and we want a float so if you want to learn more about the actual new Unity input system then let me know about down below and we can actually go over that we also want to get the grip value and set that equal to the grip action dot action dot read value and once again we want a float in here we can then set the animator so anim dot set flow and the animator that came with the hands we just downloaded have two properties they have a trigger um property which we can set to the trigger value and they also have the grip value which we will set to the grip value as well and there you go that will now animate our hand so let's go back to you and let these scripts compile and then we can actually see on the right here we have two references now again with the XR toolkit we downloaded samples we downloaded we actually have all the inputs we need so what we could do is select on the left hand model so we want to select use reference for both of these and then on the trigger we're going to select this I'm going to put this in this mode and we're going to just search for the xri left hand and then you could go down to the trigger or sorry for the trigger we want the actual activate value you can see here left hand interaction activate value we don't want activate because there's actually a button and we want the actual float value of an axis here so we're going to select that one and then for the grip we're going to do the same and just type in left hand or left hand however it works and we're going to select the select value for the grip now we're going to go to the right hand and we're going to do the same we're going to select the right hand for the Trigger action we want the activate value for the right hand so we want to go down to right hand and select the activate value and for the grip we want the right hand and select value there so that will allow us to use this now we can actually set this hit play and try this out and I just noticed an error before we actually can do actually use the hands is we aren't setting our anime at 25 so what we need to do is say start and set the anim equal to get component and it up animator like that and that will get us the animator component attached to the hand we're currently trying to use so let's now reset that let the scripts reload and hit play and as you can see we can grip our hands and we can also press the trigger two to actually see the hands pinching now you can do one at a time you can grip you can play fists and now you have hands you can actually interact with like this which is pretty awesome um but you can't actually do anything with it we could throw a cube in here we won't be able to interact with it so if you did enjoy this tutorial on getting started with VR then please let me know Down Below in the comments and I will consider making a can continuous video or continue a series on this where we actually set up a bunch of different VR environments different games you can play in VR we can do how you grab and pick up things so I can show you how you interact with different elements physical buttons and stuff like that we can even do a UI menu if that's like you're interested just let me know in the comment section below what you want to see on this VR tutorial series okay guys that's it for this video I hope you've enjoyed if you did don't forget to leave a thumbs up smash that subscribe button and I will see you in the next don't forget to join the Discord Surfer down below and peace out
Info
Channel: Muddy Wolf
Views: 22,713
Rating: undefined out of 5
Keywords: 2d game dev, game dev, 3d game dev, 3d, 2d, game development, developer, game developer, unity, unity3d, unity 2d
Id: pI8l42F6ZVc
Channel Id: undefined
Length: 15min 38sec (938 seconds)
Published: Tue Jan 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.