Let's get moving in VR!! Setting Up the Locomotion System with the new input system in Unity.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone so last time we went over how to get your new project xr project up and running with a new input system and today we're going to go over how to get moving if you haven't checked out the last one i'll leave a link to it and we're going to get started as you can see in this video you'll be able to teleport and move around the scene so we'll get started here we are in unity um pretty much we left off last time where you just have the xr rig and a capsule to pick up so the first thing i'm gonna do i'm gonna add some cubes to the hand so i can pretty much just know where they are just use those as a reference for each hand and i'll make them smaller and make one for the right hand cube and that's just to give us a reference to where they are in the scene because we're gonna pretty much turn off the radiant rectus periodically so we just want to know where the hands are so first thing we're gonna do is go to the xr rig and go to xr and add a locomotion system action base and say you just want to get moving you don't want to teleport or anything you just want your character to be able to move with the controllers we can add a component here called continuous move the continuous move provider action based and there's also one for the terms you want to continuously turn return action base and it already it already comes with a snap turn if you want your controller to snap to like 45 degrees whatever degree you want to but with the continuous move we're going to set a reference to the left hand and it's going to say move right here and then with the continuous time we're going to set a reference to the right hand and then it's going to be a right hand turn and now we go play in a headset you can see i can move using my left hand controller to walk around i use this one to turn in a circle and i can quickly get up and just walk around the world and see everything all right don't come out of play let's say you want to be able to teleport so let me um turn the ease off for now and if you want to teleport you see we have this plane which is essentially our ground we're going to add a teleport area to that and then it needs a uh it has a reference to the interaction manager it needs a teleportation provider which is our locomotion system you can drag that in there as a custom reticle which is something you can make easily so we can come over here say create it through the object and create a cylinder and this can be our vertical and we're going to string it down in the y let's first zero out the position of it say 0.1 and the y you're going to make sure you take off this capsule collider because it will give you problems if you don't um i have a blue material here so i'm just call it a give this that blue material here and make it a little transparent as you can see then i'll make that a prefab it's going back to my xory or my plane where i had that teleportation area and i can put my reticle in there i can delete it from here and then now when i go into the dvr here you can see i have i can teleport with both hands set right now and i mean pressing the grip button to be able to teleport so yeah so now i can teleport with both controllers but say you want to um have your teleport activated at a button press and you don't want the controller to see the reticle the whole time so we're going to set that up now so for the left hand i'm going to set up for the left hand we're going to turn off the x-ray interactor and we're going to add a component here i'm going to add a radiant vector and now we'll call it our teleport ray and we're going to have these rest put these references in manually i'm going to be referencing the left hand so it says position action so we just go to left hand position rotation action left hand rotation select action left hand slip and names are pretty much going to match these names with the reference um this active looking active ui left hand ui um haptic feedback [Music] anchor rotation rotate anchor and translates and now this teleport ray is referencing the left hand we're going to um [Music] look at our default um default input actions and here you should see um to generate the class as a file um you might see it like this but to get that activated just click here and hit apply to generate this as a class and that's going to come in handy when we write our code um if you look at the input actions you can see that our teleport mode active is being controlled by the primary button and on the oculus the primary button is the x button on the left controller and the teleport mode cancel is controlled by the grid button and that grip button is what's going to control our teleport so when we let go of it it's going to teleport us so now we'll go to the script i also want to okay yeah so we'll go to the script now um you can create a script called teleport let it load up all right so this is my teleport script and pretty much um it's referencing the new input system so at the top we want to have a public game object to teleport ray which is the array we just created we're going to have a public boolean for a private boolean called activation threshold and um essentially when that boolean is set to true it's going to show the ray active and when it's set to false it's going to um show the way um deactivate it so here xr default input actions it's a reference to the input um that class we just created and in the private awake we're going to be referencing the left hand and as you saw on that default input map the teleport mode active is the name of the button for the map but the binding name for that button and um you can see that the left hand teleport mode active is set to perform and perform essentially just mean the button is pressed and when the button will press and hold help and when the button is pressed and held the activation threshold is set to true and then when it's um canceled the we reference the left hand again the teleport mode active cancel it said it sets it to the false and then down in the awake function or an update function we have if the activation threshold is true then it shows our teleport ray if it's set to false then it um turns it off all right and this is just to enable and disable our left hand when we press the button down here and uh if you need to pause it to look at the script go ahead and do that so you can write it out and then we'll go back to the editor and then on that xr rig we're going to add that script and then our teleport ray is going to go in here and then we can go ahead and deactivate the ray so now i'm going to vr i'm going to go up here and hit it play with my mouse you can see i turned off the left hand ray if i hit the activation button you can see it activates my teleport and i still have it to press the grip to activate the teleport so i pretty much have a activate and cancel button so if i decide i don't want to teleport over there no more just let go of the button all right and then for that ray as well if you want it to be a curved ray just go down to the xray interactor and with this line type you can go to a bell's ear curve and that would make it that curve ray that you see in a lot of vr games um but let's say you still want to use your left hand to pick up things and um to see things so to customize the rays um let's go back to the left hand side back on so to change that to be able to still use your left hand but not have it show up as a teleport like you saw with the right hand uh we're going first we're going to change our plane we're going to give it a tag um we're going to give it a layer sorry we're going to give it a layer so i created a layer called ground and then we're going to make the plane a ground i'm pretty much going to turn the physics off between the two so i go to plane and set it to ground and then i go back to my left hand controller and you see i have this xray interactive on where it says um raycast mask it says everything so it's going to interact with everything but if we turn off the ground it won't interact with the ground anymore and then another thing if we um so yeah let's just happen to be our first and i'll show you that so now you still see my ray but like um when i look at the ground it's still red because the red is the invalid selection for it and i can't um do anything so my right hand is still turning white because it's still set to detect the ground but my left hand is not and i still can pick that up and everything so let's say you don't want to see these rays unless you are selecting something that's active so if you want to turn off the rays whenever invalid go back to that um so on the left-hand controller i want to scroll down to the xr interactor line visual and you can see the invalid color gradient is set to red so whenever it's looking at something that it can't interact with it's going to be red so if i come up here come in here and i click on this top right here this is the alpha value which is essentially the transparency of it so i'm going to turn that down to zero and then i'm turning this side down to zero and then for the valid gradient you can have some fun with that if you want to change the color so the beginning or the left um little tick mark is the beginning color so i can turn that to like a orange color in the in color to like a blue color just to give it a little style and then now i come into play play see this one see okay i don't have a blu-ray but as soon as i look at the capsule with my left hand is there and you can see i have the custom colors into it as well and then i still have my teleport here with the x button the primary button and i can teleport with the grip button on both controllers and um when i look at that i can still pick it up with the grip button show it pick it back up um hit x grip button teleport teleport and yeah let's move on so that's um pretty much all i have for today that's how you can add a locomotion system get up and moving in vr um essentially well i'm gonna say not a no code solution but if you just wanted to get up and get moving turn off those rays that's a no code solution but if you want to have a custom button to teleport just a simple script to get you teleporting so um let me know if you like this video uh check out the other one if you haven't already and let me know if you um what else kind of tutorials you want to see in vr and i'll talk to you guys next time you
Info
Channel: Pdot Creations
Views: 138
Rating: undefined out of 5
Keywords: Unity, Tutorial, Vive, Oculus, VirtualReality
Id: OGdM26vQrUE
Channel Id: undefined
Length: 16min 1sec (961 seconds)
Published: Mon Aug 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.