XR Toolkit 2.0 Crash Course using Unity 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there i hope you're doing well today we'll be doing a rough overview of xr toolkit 2.0 using openxr in uni 2021 we'll be covering the initial package setup basic interactions and locomotion just to name a few and this is going to be a pretty long video so get comfortable get a drink and let's get started and i imagine you're probably going to be wondering what version andrew should i be using well i'm going to be using 2021.2.13 and if you've done any vr development before you'll know that versions can change with time and how the exact workflow can differ from within six months fairly rapidly as of recently though it's slowed down so hopefully this video has a little bit more of a lifespan on it but you'll see here that i have an empty project you can see up here in the left hand corner that i am using 2021.2.13 and i've pretty much done nothing there's i haven't set up anything beforehand this is completely empty so when you set it up it should more or less look exactly like this i know i've probably moved some of my my panels around here but this is just how i like to work the first thing that we're going to be doing is getting open xr setup and if you're not familiar with what openxr is it's one of the newer standards for getting all of our different hardwares to be interpreted the same way within our program so we don't have to sit here and be like oh if it's innocuous do this if it's a vive do this uh unity system with the fact that it's implemented openxr with its new input system or just the input system probably at this point does a lot of the heavy lifting for us and is a bit of an abstraction layer between the hardware and the code that we're writing so some of this may seem a bit dense at first but know that it is saving us a lot of time and effort so let's go ahead and let's go up to our window let's go to package manager and it's going to take a second to load and we're going to want to go up to this drop down here and just go to unity registry and we can either scroll down to the bottom or let's see if we can just type it in here i'm going to type in open xr and i'm going to be using 1.3.1 i think let's see what the recommended version yup that's what it is since we're working in 2021 currently there have been some recent changes to the package manager where they're not letting us have a history of versions they're trying to prioritize stability in the engine so they're only going to give us release versions of some of these packages and i kind of understand why but for me personally i do like having the opportunity to switch between packages if there's a bug or just to make sure that the behavior that i'm getting is the intended one but enough of that side note let's hit install and then with the power of movie magic i may speed this up but in the meantime let's take a drink because that was part of the tutorial you need to make sure you have a drink i have it in this nice uh what would you call this watercolor mug or something that my brother got me for christmas if you hear the ice in there it's because it's not a hot beverage all of our glasses were dirty okay well we're still importing here yeah i feel like i'm most certainly gonna need to uh speed this up and post i usually do all right and during the process of putting in openxr we're going to give this warning and i'll just read this bottom paragraph for you it says do you want it well that actually doesn't make any sense let's just read the whole thing this project is using the new input system package but the native platform back-ends for the new input system are not enabled in the player settings this means that no input from native devices will come through do you want to enable the back-ends this is such a hard thing to read i haven't read this thing fully in such a long time if you haven't noticed but doing so will restart the editor and will disable the old engine input apis so this is kind of what i was talking about earlier we need to use these updated input systems if we want to successfully get values from our hardware so we just want to hit yes here and we're going to be doing another loading bar and your editor is going to restart that's perfectly normal don't worry too much it didn't crash on you but then the editor will reopen pretty much as we had before right now we'll go ahead and we'll exit out of this we will be coming back to the package manager to put in xr toolkit but that's going to be a whole nother process but what we're first going to need to do is configure openxr so we're going to go to file we can either go to our build settings or we can go to edit project settings we're just going to go to our project settings here i'm going to go ahead and maximize the swizz window so it's easier for us to see and you'll notice that we have this xr plugin management now if we came here before we installed open xr there was just going to be a button here that just says install xr plugin management so just in installing openxr will do that process for us but you'll notice that we have these plugin providers here we have oculus we have open xr and we have this unity mock hmd what we're going to want to do since we're using openxr since we want to target a lot of different platforms we're just going to go ahead and we're going to click that and there may be a short process here but mine seemed to do it pretty quick but you'll notice that there's going to be this little yellow triangle here we're going to want to click that because it's going to let us know what we're going to need to do to get openxr fully running within our project when this was first released there was a number of things here that we would have to click through but now it's just letting us know we need to enable an interaction profile so we'll hit edit and it's going to just bring us down to this little open xr here so we were here a moment ago it's just going to bring us down here so we can be a little bit more specific with the settings that we're using for open xr the only thing that we're really going to want to do here is we're going to have this plus sign here and you're going to want to add whatever controller that you're essentially going to be using and this is just going to be some of the values that's going to be that sort of abstraction layer that i talked about where it's going to be getting inputs from our controller and it's going to be sort of funneling them into a sort of unified interface that unity can work with and for me the valve index that's going to be all the way down at the bottom and at this point we pretty much have a vr compatible project however we're also going to be wanting to use xr toolkit we'll exit out of both of these open xr windows we'll go back to window and we'll open up the package manager and like before we'll go to our search bar and we'll type in xr toolkit and one thing you'll notice that there aren't any results for xr toolkit if you're using an earlier version like unity 2020 this it should pop up but like i said previously about the changes in the package manager we're going to have to jump through a little bit or another hoop essentially to install xr toolkit if you're watching this in the future it may have already popped up for you and you just need to install like usual but for right now if you're watching this as this video releases we're going to need to do something a little bit extra so i'm going to open up a website page right now and if we refer to that page in the documentation that we saw previously we can see that it says there are no pre-release packages for this release which is really interesting because if we go up to the version drop down here and we go to the version right before it you'll see that it specifically has xr interaction toolkit here marked as a pre-release so at this point we want to copy this com.unity.xr.interaction toolkit and then we just want to go back into unity and now that we're back in the package manager we'll click this plus sign here and we'll say add package by name and we'll just want to paste that in there and we'll hit add and it's going to start to install the package for us like i said before this may not be a process that you need to go through but i guess we're do you know this is what we got to do right now and with the introduction of 2.0 they've added some new interaction layer mask stuff we're not going to be dealing with this too much but we'll just go ahead and hit i made a backup go ahead alright and it looks like it's done let's go back up to the upper left here and we'll go to the current unity we'll go to in in project well let's clear our search here and it should come up xr interaction toolkit at the bottom of your packages within your project what we're now going to want to do is we're going to want to expand this arrow here and there's going to be the samples we'll click that as well one thing to take note of is that we are indeed in 2.0 and it is currently marked as release which we'll see again there so i'm not exactly sure what the current status is or who manages whether it's on the toolkit side of things or the package manager we're not going to worry about it too much what we will need to do is input our starter assets so we'll click that and what this is going to have is a bunch of input settings that we're not going to have to set up manually it's really going to accelerate the process for getting our project up and off the ground this is something you do not want to do manually it's not a very fun process but we will be taking a brief look at these assets to see if we want to make adjustments in the future if or if you need to for your project so now that we have all that done let's exit out of the package manager and technically we've done all of the painful project setup so now the first thing that we're going to do well the first thing i'm going to do is i'm going to go over to my notes and we're going to set up our camera rig but before we even do that we're going to need a bit of a floor to kind of know what's going on within our scene so i'm going to right-click in my hierarchy and i'm going to go to 3d object and i'm just going to hit plain so now we have a bit of a floor to work with then we're going to right click again in our hierarchy and we're going to go down to xr where this is going to have a bunch of useful already set up things that's going to make the process a little bit quicker for setting up our project usually for a project i would hit access xr origin action based which we'll just do that right now just so we can take a look at it and we'll see here that it has a number of sub-objects to it it has this camera offset it has the camera itself and these two controllers the xr origin is essentially going to be our play space and it's going to have some functionality for rotating the player as well as moving them but that's not something that we're going to be interfacing with directly this is usually going to be called from things that are going to be teleporting the player within our project but something we will be doing in just a moment is working with the tracking origin mode but we're not going to be specifically starting with this one because on the controllers it has all of this interaction stuff already set up for us which we'll be setting up ourselves in the future so we'll be disabling this for the time being or if you can do i'll just go ahead and delete it actually and we'll come back into our hierarchy and right click and we'll go to xr and we'll just click this xr origin down here and when we click that we'll get something that looks very similar to that xr origin we just saw but if we expand this you'll notice that we don't have our controllers here because like again we're going to be setting those up ourselves because we're going to be starting with a different type of interactor which we'll talk about more in just a second but what we will do is that currently the tracking mode is not specified where this is for older headsets generally if they only have three degrees of freedom meaning they only track rotation this would be the old like your gear vr or oculus go or google cardboard we've largely moved on from that and even the more off the shelf sort of headsets have six degrees of freedom meaning they track the position as well so all we're going to need to do here is just go from not specified to floor since this is most likely the type of headset you're going to be using and this includes things like the oculus quest vive or index and we're going to test this in just a second but let's click on our main camera really quick and you'll notice like before like always on our camera we have a camera component but more specifically we have this track pose driver that's already set up for us which already has references to some input actions which we will talk about briefly in a little bit where it's already going to be getting the position of our headset as well as rotation and applying it to our main camera here and we're going to test that in just a second so right now if you haven't set up your play space yet turn it on now which i haven't done so i'm going to do that now so as all of that sort of starts to power on i'm going to go ahead and i'm going to save my scene and i'm going to hit play and i'm currently using steamvr so if i go ahead and drag that window over you'll see that i have both of my lighthouses on as well as my headset that's standing by for input so i'm going to pick my headset up and you'll see that it's already beginning to track its position and rotation so we really haven't even done anything extra with xlr toolkit or the inputs or anything like that but we're getting tracking in our headset already so at this point that should work if that didn't work you may want to review some of the steps that i've already gone over and see if there's something that you may have missed because now this is where we're going to get into the xr toolkit side of things where now we need to set up our controllers so kind of like we saw with that other xr origin let's come to our camera offset and we're going to create a couple of empty game objects we'll have one that we'll just call left hand i'm going to duplicate this by just hitting control d and then i'm going to call this right hand and then we can select both select both of those game objects and we're going to add the xr controller component more specifically we're going to be using the action based version and we want to be using action based because if you remember when we were putting open xr into our project it gave us that little prompt for using the new input system and action based essentially means new input system and you'll see why in just a second so if we add these to our empty game objects here you'll see that we now have all of these different actions here which it's going to be its position of the controller the rotation the current tracking status as well as all of these different inputs from haptics to activating and selecting i know that's a lot to take in but we're going to kind of be stepping through a lot of it so don't worry too much about it but for our controllers to work we need to have some actions here and this may look a little bit familiar because if we go back to our main camera you'll see that it also had these sort of input action type things so if we go back to our controller if we wanted to we can hit this plus sign we can add where we can add a similar setup but as you can imagine going through all of these different actions would be kind of a pain so this is where those like sample assets that we put into previously are going to come into play and we can actually find those from our samples folder xr interaction toolkit start our assets and it's going to be these default input actions here which this is also a lot to take in and we'll look at this more closely in just a second but let's apply these to our controllers here and you may be wondering how do we do that well it's pretty simple we also have these different presets that we can apply to our controllers so we don't have to drop them in manually so we'll go to our left hand here we can hit this little icon with these two little slider bars here and you'll see that we have a preset for our left and our right controller this most likely looks like this on your screen but if you drag the slider all the way to the left it'll give you a list view so it's a little bit easier to see and i'm just going to hit the left controller exit out of that i'm going to do the same thing for my right controller and right now we pretty much almost were nearly there for actually having tracked controllers so what we need to do now is that for some reason the controllers are not responsible for activating these actions so we need an extra component to activate those as well so we'll go to you can do this on an empty game object but i like doing it on the xr origin it is the interaction or the input action manager so add that and we'll just need to add that asset that i just pointed out to you earlier which is the xri default input actions and at this point we technically have all of our input and our tracking and all of that set up but that was a lot of kind of input mumbo jumbo that may may not make a lot of sense to you right now so let's take a second and let's explain that a little bit further so if we double click on this xri default input actions asset and then we'll expand it this is essentially where the values from our controller are sort of being abstracted into things that we can use within our project so if we click either the left or the right hand you'll see that we have all of these different actions and the easiest one to understand is probably going to be the position here so if we expand that we'll see that we get a vector3 value from it and this vector3 value is being received from our device position more specifically our left hand xr controller so what this is essentially doing is getting the values from our controller and kind of giving them a name the one thing that we're going to be working with in a bit with interactables is selecting activating as well as pressing the ui we have a ton of different actions here that aren't as important to the sort of core functionality but are useful when it comes to interacting with user interface or teleporting and things like that but as a quick primer before we get into actual interactions the select currently is more or less how we pick up an object and if we wanted to see we can currently select an object by pressing the grip if you wanted to come in here and maybe change this value to something else you would come in here into your xr controller specifically the left hand optional controls and you would have all of these different inputs that you can use i wouldn't advise doing this right now unless you are a bit more advanced because some of these work some of them are a bit more difficult to work with but it's just good to know right now that it's here you can also have multiple inputs for a particular action as well and i have an older video that's dedicated to going into all of this more in depth so this we're just kind of scratching the surface here and i'll probably link that video down in the description so i think that's enough for input actions we largely don't have to worry about it right now but it's good to be aware that it's there so exit out of that and now let's hit play to make sure our project is all working since we don't have any objects for our hands we're not really going to be able to check to see if our tracking is working particularly well but if we go into our scene view here and we just select one of our controllers i'm going to activate my right controller right now and once i put on my headset you'll see in my scene view here that the transform of my hand is actually moving so that looks like it's working perfectly well so you should be getting some values within your inspector when your hand has been selected if you look in my upper right hand corner here you can see that the position and rotation are being updated so everything looks to be working as expected and i think that's enough for our first little session so let's take a quick break and we'll be back in five minutes well not real time five minutes probably like five seconds alright see you then [Music] [Music] hello and welcome back it's time to do the fun part interactions which is probably why you're here to begin with but we're going to be talking about interactors interactables how they talk to one another and some of the things that we can take advantage of when we're making things for our project but let's talk a little bit more about what an interactable is it's something that we can pick up and it's something that we can use your hand would be an interactor so your hand is going to be the interactor and the screwdriver is going to be the interactable there's a few different things that interactables can do or the things that we can sort of tap into essentially when your hand touches the screwdriver or the interactable that's known as a hover when you grab it that's known as a select but then we have another action called the activate action when you're holding the object with the grip button like we looked at previously and you pull the trigger that is the activate action and let's set something up or set up a grabbable object but before we need that we need a way to visualize our controllers and this is where i usually just use spheres if you have a hand asset you can use you're more than welcome to do that but for right now i don't want you to have to go and download something so we're going to come into our hierarchy here and i'm going to create a 3d object then i'm just going to make it a sphere i don't have any materials right now so we can actually make one really quick and you can make it whatever color you want i'm just going to call this m underscore hands and i'm just going to make mine i have all these beautiful swatches here let's make it this color this is where the the fun customization part of the project you can make it whatever color you want but i'm just going to make my sphere a different color here drag and drop that on there one thing that we'll want to do is remove the collider on it as well or we're going to get some pretty weird results i'd imagine or we'll also want to change the scale to something a bit more usable i also want to rename this so you can select it and you can hit f2 and then you can just type hand and we could turn that into a prefab by just dragging it into our assets folder and now we have this little object that we can use to show where our hands are in the scene and usually you would probably just think oh yeah i could just child this object onto the hand here but that means it's always going to be displayed and xr toolkit isn't going to be able to use it so we'll just delete that now because within the xr controller we have this model section here and we have this model prefab so what this will do is if we select both of our controllers and we'll drag our prefab into it this will be spawned once our scene starts and this is useful because when you pick up an object it's going to disable this hand prefab that we have so it's not sitting on top of the object that we've picked up and if we want to we can hit play again to make sure that that's working as expected so with my headset on you'll see that i'm moving my controller and our sphere is in the correct place and it's following correctly with our controller and if we want to we can come in here within our hierarchy and you'll see that we have these additional assets are not assets but game objects that are created when our project starts if we wanted to change the position or rotation of our hand we also have this model parent here but this is going to be the version of our hand prefab that's going to be instantiated every time we start our project that's pretty much it for that and we now need to actually add the interactor to our controller i did sort of mention that our hand is essentially interactor but there are different kinds of interactors that we can work with we can use ones that use triggers so they're going to be more behaving like a hand so your hand needs to get nearly interactable before you can use it but we have other ones that are based on using raycasting so if you don't want to bend over to pick something up and you want to just point at it and be able to pick it up we can use ray ray interactors as well we're not going to be using those right now because uh direct interactors are usually going to be more most likely what you're going to be working with but there are also different kinds of interactors that aren't sort of related to your head at all we have sockets and things like that as well where if you wanted to attach something to your shoulder or your head or something like that that would be a socket so it's still going to be looking for those interactors but those are going to be essentially behaving on their own and we'll probably look into those very briefly as well so for the interactor that's going to be closest to what we sort of think of as a hand that's going to be called the direct interactor so if we come into our inspector here we'll just write xr direct interactor and there's a lot of different settings and things that we can use here for one if you wanted to have it based on when you are actually picking up an object whether you want to be a toggle or whenever the value changes or if you just want once the object is picked up they can't necessarily get rid of it but we're just going to keep this setting as is if you have a lot of different sort of interactables in your scene and you only want specific interactors to be able to interact with those things you would put them on the same layer mask we're not going to be working with that but that's just something good to know or if you want to have an interactable that is automatically selected when your project starts we have this here as well but the main thing that we're going to be looking at is selecting both of our hands here and checking this hide controller on select because if you remember we put that prefab in our hand slot earlier so when we if we check this box it'll hide that game object when we pick up an object and now we need something to actually pick up so let's come over into our hierarchy again and we'll right click and we'll just create a cube and we'll hold ctrl and we'll just drag up and what control it's going to do it's going to snap it to increments of 0.25 to make sure it's completely flush with our ground if we want to we can apply our our beautiful material that we made earlier to it if we want to and now all we need to do is come into xr and it already has a handy dandy grab interactable for us to use so if we click that it's going to be hidden in your box here but if we click and drag up on that you'll see that we have this cube here that has a box collider a rigid body and a grab interactable however before we get into that one thing i completely almost glazed over is if we go back to our controllers you'll see that we added our direct interactor here but you'd if you remember i mentioned that it works with a trigger we need to make sure we add that if we don't it would actually give us a warning so i'm going to just show you that really quick if we do hit play it's going to tell us that our direct interactor does not have a required collider set as a trigger and now we come to our controllers again and we're going to add a sphere collider and we'll make sure to mark it as a trigger and we're just going to make this a little bit smaller i'm going to go with 0.1 but you can play around this to see what works best for you so now that's set up correctly let's go back to our grab interactable and interactables and xr toolkit are pretty i wouldn't say they're complex but there's a lot of things to sort of learn and grasp so don't try and get everything in this first go there are a lot of other great videos on youtube that will go into this in more detail like i said this whole video is a bit of a brief overview just to kind of get you started but what we do have or things that i will sort of point out to you is the movement type we have instantaneous velocity and kinematic instantaneous is more or less moving it via transform so it's not really going to have any collision and it's going to follow directly with the hand kinematic basically means that you're interactable once you grab it can interact with other physics objects and then velocity tracking means it will collide with any other collider within your scene most people opt in for the velocity tracking but if you have a very specific game it may be useful to exercise one of these other two options but for now since velocity tracking is the most interesting we're just going to click that and now that we have that set up let's just see if this works let's hit play and now i've grabbed my object and i've moved back to my microphone you'll see that we have actually successfully picked up our object and we can move it around so everything looks to be working as expected there what we will also do now is talk about some of those events that i kind of briefly mentioned when we were looking at some of the input actions is the interactable events down here there's a lot that you can work with but we're not going to be going over all of them right now the biggest things we need to know about are the sort of things we've already touched on which includes hovering selecting as well as activating and i'll show a quick example of this in just a second but let's not move on from interactors and interactables just yet what we can also do is have those socket interactors that i've already talked about as well so if we change up our scene view here a little bit and i go back into my hierarchy and i go to xr you'll see that we also have the socket interactable or just the socket interactor sorry where if we take that and we move it up a little bit you'll see that much like our direct interactor it also uses a collider where we can usually use this as some sort of basic inventory system where it is connected to our head or we use it as a sort of belt or something like that but just to show you a brief example if we come over to the xr socket interactor you'll remember that we did point out the starting selected interactable from before let's just click and drag our interactable into this and if we hit play we'll go to our scene view really quick you'll see that the socket has essentially grabbed our interactable already and if we want to we can actually take the interactable from the socket and give it back to it so i'm going to do that really quick so as you can see it very much works like the direct interactor but sort of works on its own and doesn't need any input from us let's now do some quick functionality with the sort of events that we just took took a look at let's disable this socket for the time being let's go to our grab interactable and let's just have some functionality that happens when we are holding the object and we pull the trigger so when we activate it if we scroll down here we'll say activated we'll hit the plus sign and we'll just drag in the object here and we'll just like change the material or something like that on this object so we'll just hit go to its mesh filter it's material and let's just have a new beautiful material that we can use here let's just call it red for the time being and we'll just put in a beautiful red that i have here it's it is beautiful i know and we'll go back to our grab interactable scroll down again and we'll just drop in our red here the thing is if we wanted to we can then change it back to our color that we had originally you don't have to do this but i'm just going to do it for this for the time being i guess and we'll put it back when it's deactivated so you can actually see when we pull the trigger and when we release it so you know there's actually some value in doing it test this really quick and now that i'm holding my interactable if i pull the trigger you'll see it changes that red color and if i let go it changes to the blue color there we go so as you can imagine this is very useful if you're creating a weapon of some sort if you want it to fire when you pull the trigger or you have like a drill or something some sort of device with a trigger on it and the thing is about interactables not everything is going to be something that you can pick up and that you can move around and i don't believe there is a xr example for that but there is a component so if we go to our grab interactable here i'm going to duplicate it make sure it's selected and we'll remove this grab interactable and we can add the simple interactable and this is something we can't necessarily grab and move around but it is something that we can still select and hover and activate so if we wanted to let's just work with the hovering functionality for the time being and let's do kind of what we did before where if we hover it we'll change the color to red or something like that and there we go let's actually not worry about this for the time being so let's play again so if we come into our scene view really quick let's disable this grab interactable so it's a little bit easier for us to see and we just have our simple interactable and if you touch it you see that it'll now turn red so that's the sort of basics of some of the simple interactables as well as the grabable interactables and some of the interactable events that we can work with and i think that about does it for both interactors and interactables let's probably take another break and when we come back we're going to be talking about locomotion teleporting snap turning all that good stuff so see you in a bit [Music] [Music] and we're back we're going to be doing locomotion this is also time that you're supposed to take a sip of your beverage so do that now watered down store-bought cold brew it's the best okay so what we're going to be doing now is this is kind of where it doesn't get confusing but it gets a little bit more intense a little bit don't worry it's it'll be okay i promise and what we're going to be doing first is we'll set up teleporting which all of that's pretty straightforward we can do not delete but we'll disable these things within our scene and to teleport we're going to need a number of different things but i actually don't know how many things we're going to need i'm going to say three so we need we need a locomotion system we need a teleportation provider we need a teleport area and those are the three main things we actually need we'll also technically need a reactor interactor but that's not important so i think i was right we're going to go with three so and the first thing that we're going to be doing is making our plane here a teleport area so our system knows that oh i can teleport to this thing it's much like an interactable there's a lot of things that are in xr toolkit that you may not realize that interactables but they are all those things inherit from the xr base interactable you can technically if you wanted to reach down to the ground and grab it and it will actually teleport you to that position if it is actually selectable but we're not going to be doing that we basically need to tell our ground hey like this is an interactable meaning when we point at it with our array that we can actually do stuff to it so we can add a component here that we'll just call teleport area and that's actually all we need to do for that you'll notice that there's also a teleport anchor so if we come in here we'll see teleport area and then we have the anchor as well i don't know why the anchor is gigantic what would happen yeah i usually scale it down to 0.1 and then you can use this if you need the player to teleport in front of a table or console or something like that but because you can also change the direction they're gonna be facing with this anchor here and you'll see that it has this nice little gizmo that's gonna show you all that good stuff but we don't necessarily need to be working with that we're just going to be using the area for the time being and what i also like to do usually is i come in here i create an empty object sometimes i may child it even to the xr origin and i would just call it locomotion i think we might try and do smooth locomotion before the end of this video so this might come back to bite us i'm not exactly sure we'll find out so we'll reset the transform and we're going to go to those three things that i talked about we have the locomotion system which this essentially manages all of the different sort of providers or things that are going to be changing the position and the rotation of the xr origin kind of how i mentioned at the very beginning of the video that's where all this functionality is however if you have multiple things that are trying to move the origin at the same time you may get some unpredictable or undesirable results so the system basically says hey this thing is already moving the origin you need to essentially wait your turn so you don't want to accidentally like snap rotate when you're teleporting or smooth locomotion when you're doing other things but this is also useful if you want to build a climbing system or something like that because as you're climbing you necessarily don't want to be able to smooth locomotion away from the wall that you're climbing or something like that okay so let's drag in our xr origin you don't need to set up these references here it'll do them automatically but i'm a sociopath and that's just what i like to do alright so we'll go to teleportation provider now and you'll know that it needs a locomotion system so join in with me with being a sociopath and dragging our locomotion system into that great job you're also gonna say declaration diploma will be in the mail and now that we've done that we may what should we do snap turning right now we'll just we can also have another provider which is the snap turn or you can use the continuous we'll control z that the continuous turn provider which makes you smooth or makes you turn smoothly but i'm just going to have it snap for the time being make sure that this is going to be action based one as well or it's not going to work and we'll work on this in just a second we're not going to worry about about it too much but you'll kind of see what the point of the locomotion system is as we're adding these different providers to it it's going to need to kind of say hey like this thing's working you're not supposed don't do anything right now but let's also add the locomotion system there cool but for us to effectively use our teleport area we need a ray interactor unfortunately and that's where sort of the xr toolkit is sort of lacking a little bit or is currently working on is the use of these multiple interactors i won't get up on my soapbox about how it sets how it currently does things and how i would do things differently point is i do have a video that shows you how to use multiple interactors at once without too much of a headache it's probably a little bit easier to do now but we're not going to get into that too much it's just a little bit a little bit too in-depth for this video but we're good what we're going to do hopefully this is the easiest way if we come into our hierarchy we'll go to xr and we'll just hits ray interactor action based and this is going to be very similar to that thing we saw with the original xr origin and we'll come to our controller here we'll actually drag it up here and we'll just we'll use it on our left hand so let's let's disable this left hand that we currently have and we'll just call this our left hand ray or something like that and much like before we'll apply our left-handed asset preset and in theory this should all already be good to go if we wanted to we could put the model prefab in here as well but we do have this line visual that we're going to see in a moment that is going to help us know where our controller is if we go to our teleport area again though this does have some different settings or at least the one that is going to be particularly helpful to you which is when you want to actually teleport if you want to teleport once you actually select the object or when you're done selecting it or when you've activated it or when you've deactivated it most commonly i just leave this on select exited because if you accidentally press down to teleport on something you do if you're doing it by accident you may want to point it somewhere else and release so you can sort of cancel that teleport so we're just going to leave it on that for the time being all right so let's hit play and let's see if this works so you'll see here that i have my ring but it's a little bit difficult to see because when i point at the ground it's actually white to make that a little bit easier let's apply our our hands material to that and let's try that again all that looks to be working as expected let's now set up that snap turn provider so let's go back to our locomotion and we'll see that we need to set up some sort of action here where much like our controllers we can use a reference to those input actions that's coming from our starter assets it's a lot of assets there but we'll click on this little circle to find it and we'll just type in turn and we'll have our left and our right make sure whatever controller that you're clicking on you're using the right action for it so i'm just going to select the left hand turn right now and you'll see that i have my left hand snap turn action and the turn action there and all we need to do now is just hit play and i can teleport and i can move my joystick left to right to snap turn and all that's working as expected i feel like i have to say that every time i demo something i'm not doing it on purpose it's just a habit i guess at this point so now let's move on to some smooth locomotion and hopefully this is going to work for us okay but we'll figure it out it's no worries so we'll add another component to our locomotion system that we'll call continuous move provider i keep calling it smooth locomotion but it's i keep getting it confused with other namings but it's going to be that continuous move provider make sure it's action based drag that locomotion system and instead of our left hand we're going to use our right hand so we're going to use a reference we're going to come in here we're going to type in move and it's going to show our right hand move and this is where this gets a little interesting i don't know if we're biting off a little bit more than we can chew at the moment but i this is so again this is a bit of a crash course we're actually going to set up an input action so if we want to you'll see why we're doing it in a second but if we click this i don't know if we can double click that yes we can it's going to bring it up in this input action window that we saw earlier but if you'll notice that this is currently left empty you'll notice that it doesn't have the arrow there on the left hand it does so as of right now xr toolkit when they set this up they said oh they're probably only going to use movement on the left hand for whatever reason so let's actually create our own little move action for our right controller so if we select this we'll go to move we'll note that it's already set up correctly so we're looking to get a value from it of type vector 2. you don't have to worry about that if you want to know more about this whole stuff i would recommend looking into some more general input videos because this is a very it's a very deep system and it even i'm not going to pretend to know all the ins and outs of it but what we're all we need to do is add a binding and then what we're going to do is we're going to go to a path i'm going to go to our xr controller make sure we go to our right hand specifically optional controls and we're going to get any inputs here that actually create a vector 2. so we want to use the joystick to move so we're going to use the primary axis make sure at this point that you hit save and you know that it's saved correctly if that little asterisk that's on the left there is no longer there and if we want to be super completionist we'll double check this this is going to be in the control scheme continuous move we'll just add it there as well this doesn't really matter for the time being but we're just doing it to be consistent and also to show you that asterisk that's primary while i did it so we could save that cool so now let's go back to our locomotion make sure that's all set up correctly and now let's hit play and this may be difficult to tell but you'll see that i'm actually smooth moving throughout my little level here and like i've said previously it's all working as expected one thing that you can also do is as of right now we're just moving the extra origin but the thing is there is an extra thing that we would need to prevent us from walking through walls and things like that so this is maybe the section that this all comes crumbling down we'll discover together but if we go to our x our origin here what we're going to do is we're going to add a oh hopefully everyone in the name was it if i could spell it correctly character controller driver and we'll also want to add a character controller now actually i don't know if you can put this on a separate game object but i know we need to have the character controller here on the xr origin but you know what let's actually let's remove this and i'm going to put it on the locomotion so let's put compress all of those take that and that makes it easier for us to drop in our locomotion provider and let's click on our origin again and we'll get a better look at it and with every character controller we have our little capsule here and i'm just going to move it up by a meter and that looks good let's hit play and we'll actually actually don't know if this is going to work and it may be easier to see within our scene view and it actually looks to be working if i zoom out here and the thing about this character controller driver is that the capsule for the character is going to only update when the player moves and this is to prevent from if you're trying to reach over tables and things like that the collider isn't going to push you away but as i'm moving around you can see that the capsule is following the camera and is following the height of it as well and that's all working as intended but that largely does it for a lot of the core stuff that we're going to be working with one thing that i didn't consider doing was using the ray interactor for actually pressing buttons and doing ui interfaces because that is almost a complete video in and of itself so let's just see if we could do like a quick and dirty version so if we zoom out here let's create a ui and we'll go to button i'm just going to use the current legacy button because i don't need to install text mesh pro at the moment and usually when working with ui i it's usually best to scale down the canvas so what we're going to do is we're going to go to our render mode go to world space and i'm just going to do this like point zero zero one we'll just try that i usually use point zero five i think but we'll see and we'll also set the position that looks okay actually let's do a thousand and the width and a thousand in the height we'll move it away from the center move it up and we'll center our button here that may that may be too small actually so let's now it looks see this is these are the things of input that are not fun i think that'll probably be fine let's just raise that up a little bit like i said we're doing this by the seat of our pants now i did not plan on doing this but the thing is when you use a canvas there are a number of different things that we need to add for our ray to interact with it properly we're going to need an updated input module as well as the proper graphic raycaster which essentially means hey we need the raycaster from our hand to be able to actually hit our canvas so with our event system selected we'll say replace input system ui input module but i believe this isn't even the one that we want because if we add if we remove this or actually let's delete it entirely because if we go to xr we'll go to ui event system it'll actually have the proper input module for us and also now i'm second guessing this canvas as well so let's delete that this is why i tried to do this stuff live so you could see me mess up and then you'll go oh andrew you screwed up this is how you're supposed to do it so you know we're both learning here we're both learning so we'll actually do xr ey canvas and it's going to have that track device graphic ray caster where i actually don't even know if we need this normal raycaster but we'll leave it there now where it's actually going to let us hit the button that we're putting on here but what's nice is actually send up the render mode and the event camera so that's actually super helpful we should do it like that from now on but now our canvas is a real big boy so we got to make them smaller so we'll do what we did previously and we'll do 0.01 and for the size i usually 500 okay this is actually looking a lot better this is actually a little bit more similar to what i'm used to so i think everything is good let's hit play and we'll see if this works make sure you're using the controller that has the actual ray interactor on it and as you can see we can point on our button we're going to get those hover events and then when we pull the trigger we can actually click it but that's pretty much it for that all right and i think that about does it i think we did everything with quite a decent degree of success so no particular issues hopefully you learned something hopefully you like this video um hopefully it wasn't too confusing with me just sort of doing it off the cuff like this but i thought it would just be a good time for us to sit down and just hang out and put it put it together together put it together together yeah i mean i think that's the only way you can say that but if you have any questions or comments feel free to leave them below i do answer almost all of them if i feel like i actually have an answer for it i think i may do more xr toolkit videos like this in the future sort of the long form and maybe some deep dives into particular mechanics and things like that maybe we can talk about the interaction manager or multi-hand interactions and all that good stuff once xr toolkit continues to get more of those uh pretty intense features but i think that's it for me thanks for watching i'll see you around goodbye but before i go for good i would like to thank all of my wonderful patrons that continue to support me month after month so i can make videos like this i'd specifically like to thank todd andler andreas brillin balthazar juan pyeongchoi spectre xr mark allen and mark a caroff and now this is the actual end of the video i'll see you all in the next one
Info
Channel: Andrew
Views: 76,447
Rating: undefined out of 5
Keywords: Unity, XR Toolkit, Unity 2021, Unity 2022, Unity XR, OpenXR, Beginner VR, Beginner XR, XR Toolkit Tutorial, Unity XR Tutorial, VR Game Unity 2021
Id: 5ZBkEYUyBWQ
Channel Id: undefined
Length: 49min 40sec (2980 seconds)
Published: Fri Apr 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.