How to do Continuous Movement in Unity VR | OpenXR Locomotion Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm thinking this will be a quick one today  so let's jump into it while I'm building this   scene up in the background i want to talk about  a few different types of movement so there's two   main ones there's teleportation which is usually  the intro type of movement for vr users because   it doesn't cause motion sickness and teleportation  is a good alternative option if your game requires   a continuous movement like in a first person  shooter where your character is actually gliding   around because users will not feel like they're  moving but then their peripheral vision tells   them they're moving and that's what causes the  motion sickness it does require a user to be in vr   and use that for several days or weeks to get used  to that kind of movement so a lot of players won't   even play a game if there's not a teleportation  option so just keep that in mind when you're   developing your game today we're going to talk  about continuous movement because it's the easiest   and also the most likely to be used in your  game so let's jump into it first we're going   to go ahead and do all the setup for standard vr  stuff so if you haven't seen my intro to vr video   check that one out and that will walk you  through the steps to actually getting all this   set up installing OpenXR plugin will cause our  application to restart because it's going to go   back behind the scenes and change the input system  from the old system to the new system and we also   want the xr interaction toolkit and inside the xr  interaction toolkit make sure to grab the default   input action sample unless you want to set all the  controls up by hand and with that done we go back   to here and we select open xr fix all there we go  now before we add the xr rig to our scene we're   going to go into the xr interaction toolkit so  from assets go to samples xr interaction toolkit   the whatever package it is and then inside of here  you're gonna click on each one of these presets   and add it to your action based controller or  the snap turn provider move provider all of those   from here we can now right click inside of the  hierarchy add an xr room scale rig action based   and I'm going to reset that to 0 and move it to  where i want it in the scene in order to get this   to move we need to add a few things to the xr rig  so first we're going to add a input action manager   inside of the action assets for this component  we're going to drag in this XRI default actions   make sure there's only one in here inside  the hierarchy click on the xr rig right click   go to xr and then we're going to add a action  based locomotion system and this is going to   come preset with a locomotion system script which  we would need to set the xr rig it's going to have   a teleportation provider and a snap turn provider  we're not doing teleportation today so I'm going   to right click on this and remove it the snap turn  is super easy to set up it actually already is set   up it comes preset if you have added these presets  it'll come preset with the actions already set up   and you just need to uncheck the hand that you're  not going to be using usually snap turns are   performed on your right hand so we're going to  uncheck the left hand action that way you can   only perform the action with your right hand and  if you wanted this to be a continuous turn instead   all you have to do is add a component and then  we're going to go to xr locomotion and select the   continuous turn provider action based make sure  the locomotion system script is set and then again   use the hand and you'll have to disable the snap  turn provider or remove it completely and now you   can very easily switch back and forth between the  snap turn and continuous turn just by checking or   unchecking one of these also inside of the snap  turn provider you can adjust how many degrees   your character will get adjusted every  time you bump the thumbstick and also   debounce time is essentially a delay between when  you just performed a snap turn to when you can   perform another one prevents you from accidentally  double hitting it or something like that now let's   set up the movement we already removed the  teleportation provider we're going to go into   xr locomotion and add a continuous move provider  action based make sure to set the locomotion   system and motion is usually performed with  the left hand so we're going to uncheck the   right hand motion also you can adjust the move  speed and you can set when gravity is performed   so I'm going to go ahead and set it to immediately  now two more components we need to add before this   will actually work go back up to your xr rig  we're going to add a character controller and   this is a little glitching box I'm gonna set this  up to one so it is two meters high you can adjust   the radius to be smaller if you want and we're  also going to add a character controller driver   make sure to set the locomotion system for this  and in here you can set the minimum height and   the maximum height that your character can become  and this will automatically adjust from the floor   to the camera height for the head mounted display  I'm gonna split my screen so that you guys can see   what actually happens when I try this out  one thing I notice right off the bat is that   only one controller is being tracked so the other  controller you see there's no laser coming off of   it and I've noticed this for the last couple of  versions of this open xr it hasn't set the input   actions for the right hand controller correctly  see in here all of the presets are set to the   left hand even though this is the right hand  controller so real quick I'm gonna go in here and   adjust all of these to be the right hand  versions and I also want to increase the   speed a little bit swamp this up to five and let's  try this out there we go so you see both of the   controllers are being tracked now I can move them  separately it wasn't even taking into account the   right hand controller so weird preset i think  they'll uh fix that in a later point so you can   notice that i can move around and move up onto  these things here and if i actually select the xr   rig you can see the character controller you see  how the actual character controller isn't moving   when I move my head or when i stand up or turn so  we need to go in and adjust that and I've come up   with a workaround I'll show you guys that real  quick if we look into the character controller   driver's code we can see when it actually updates  the character controller and all we want to do is   make it update every single update we want it  to re-update the character controller's position   because the head mounted display is always going  to be moving it's dynamic so if we scroll down   to the update character controller this is the  method that we want to copy we don't actually   want to change it here because this is code  that is controlled by unity and it could be   modified in the future so the workaround right  now is to go into the xr rig and we're going to   add a new script and we're just going to call  this character movement helper inside of this   new class we want to paste the method that we  copied from the character controller driver   and we're going to want to call that method  every time there's an update and we're also   going to need to add all of these variables  I'm going to rename them without the m   and we just need to make each of them up here so  we want an xr rig we want a character controller   a min height and a max height the min height max  height we can actually get from the character   controller driver so for these I'm going to say  driver mid height and driver max height that way   we don't get confused by having two different  min heights and max heights and inside of the   start method we just need to instantiate each of  these make sure to save all of this and then let's   go back into unity and run it and you can see the  character controller now is dynamically adjusting   to where we move and the height perfect so now  if I walk up the stairs and then slide over to   the side it will adjust me accordingly and it  won't think that I'm still up on the ledge even   though I've fallen off so a lot of these little  edge cases this fixes here and also has the added   bonus of me not being able to push into the wall  there you have it let me know in the comments if   this works for you if this was a good step-by-step  breakdown of how to actually do the vr movement   and let me know what improvements you made if  this was useful to you at all if you used any   of the code please give me a like on the video it  really helps me out and you know the algorithm in   future videos I'm going to talk about how to do  teleportation how to do climbing zero g movement   maybe some Spider-Man type swinging grappling  hooks all that kind of stuff so please subscribe   if you're interested in more vr content and as  usual I am super active in the comments section   so if you run into any specific issues or bugs or  something you can't understand just drop a comment   and I will respond in probably less than an hour  so until next video just find me in the comments you
Info
Channel: Justin P Barnett - VR Game Dev
Views: 13,385
Rating: undefined out of 5
Keywords: Justin P Barnett, unity xr, unity new input system, xr interaction toolkit, unity vr tutorial, beginner, character controller, vr continuous movement, continuous movement vr, continuous movement, continuous movement unity, unity vr continuous movement, vr movement, vr development, vr movement unity, vr locomotion, vr locomotion unity, unity xr interaction toolkit, unity vr tutorial oculus quest, new input system unity, how to move in vr, unity 2021, snap turning vr, movement
Id: _Zrde_WTaiI
Channel Id: undefined
Length: 9min 15sec (555 seconds)
Published: Wed Mar 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.