Smooth and Snap Rotation for Virtual Reality Player in Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
being able to turn around in vr can be a big challenge for some players take for example players who have small play spaces and can't really punch in any direction without risk of punching their computer or for example content creators who want to constantly be facing a camera so that way they can get good reactions on their content this is where snap and smooth rotation can really come into play with a lot of vr games this will allow for us to be able to rotate either smoothly or quickly when we're moving around in a virtual world so in this tutorial i'm going to show you how to set up some very simple smooth and snap rotation that you can set up in your vr game but before we go ahead and jump into that if you enjoy this video and want to see more just like this one be sure to like and subscribe button down below and also while you're down there consider supporting me on patreon there's a link in the description you don't have to but it's a great way to help support the channel with that let's jump right into the video now before i start doing anything um i want to say right now i'm doing this at the beginning as opposed to it i'm showing you this testing at the beginning as opposed to at the end i've read some of your guys comments and seen how some of you guys might prefer to have uh this kind of review beforehand as opposed to at the end so i'd like your guys's feedback because i don't really know how many people actually preferred at the end how many preferred at the beginning um i'm just kind of genuinely curious to see um if you guys have like a preferred uh if there's a preferred way that you guys would like to see this structure when you guys are going through these tutorials so um i i'm trying something different let me know in the comments if you guys like seeing these kinds of uh testing bits at the beginning or at the end or maybe even both so um anyways with out of the way let's go ahead and i will show you how all of this functions so before i do anything as well i want to say right now this is going to be rotating our whole player space not necessarily the player itself and what i mean by that is my the center of my steamvr playspace is roughly over there somewhere so we're actually going to be rotating around axis at that point not necessarily where i'm standing and that's just to do with the vr pawn i'll talk about that a little bit more in the tutorial and tell you why it is um that that our setup is going to function like this um so anyways on my right hand i have smooth rotation set up on my left hand i have snap rotation so i can go and show you what this looks like so smooth rotation here you can see i don't know how clearly you guys will be able to see it but there's roughly a center point right there that you should be able to see we're kind of rotating around but you can see we're rotating around um this is actually using a multiplier and you'll be able to see that in the uh tutorial itself how to change that multiplier if you want to increase or decrease the speed on the smooth rotation snap rotation uh if i recall this is going at 45 degree increments so let me see if i can get like a better angle here for this let's do maybe like that so if i go and do snap rotation this should snap me 45 degrees and it does so this is this is something that's a little bit more difficult to kind of get the hang of too just because it's not quite as smooth of a transition um but i am snapping around in 45 degree increments and i can see that i am moving around a center point it looks like um so anyways that that's our snap rotation our left hand snap rotation our right hand is smooth rotation i'm personally more fond of the smooth rotation it's just a lot easier to see how we're moving and all that um but anyways that this is what the final version is going to look like um with that let's go and jump into unreal engine and i can show you exactly how all this is done so let's go and get started in implementing this whole rotating play space for our vr player so um i'll i'll talk a little bit more about how this all works and why it works the way it does so you guys have a full understanding as to how this rotating player will work so let's go ahead and get started by actually opening up our player so i'm going to jump into the vr template uh folder blueprints and vr pawn we're just going to use the default player pawn that you should have regardless of it if you're in unreal engine 4 or unreal engine 5 or anything like that so here in our player here this is our default vr pawn and the reason that we're actually going to be rotating our whole play space and not necessarily just the player itself is because the way that this vr pawn is set up the vr pawn actually has this single default scene root and this default scene root essentially acts as the center of our play space and in order to do this we're going to be rotating our whole pond which means that we're we're essentially rotating our whole play space not just the pawn itself so hopefully that clears some things up in case you're curious as to why we're rotating the whole play space and not just the player um just because play space is just because we're rotating the pawn itself not just the camera and motion controllers in this tutorial um so let's go ahead and get started with actually implementing this so i'm going to do both a smooth and a snap rotation so that way we can uh try both of these out and see how these work so first thing we're going to need is we're going to need some at some uh input from our thumbsticks that way you can actually trigger this rotation so in order to do this i am going to grab our in our project settings let's start here in our project settings and input under axis mappings we're going to be using our movement axis left x and our movement axis right x this is left and right on each of our thumb stick this one for our left thumbstick and this one for our right thumbstick let's go and grab each of these so we're going to grab movement axis left x and movement axis right x so like i said this this movement axis right x means that for our right motion controller when we move our thumb stick left and right we're going to get some axis value depending on how far we're pushing our thumb stick and same one for this one this is going to be for our left hand and that should be for oculus uh oculus controllers index uh i believe there's a few others mixed in there you can see all of them here yeah mixed reality and vive in there are both in there as well so here we're going to do two forms of rotation we're going to use our movement axis left x for snap rotation and we'll use our right axis our movement axis right x this is going to be for our smooth rotation so we'll take both of these uh and we'll do different types of rotation for each one so that way you can have uh you can have both types of rotation so let's start down here with our movement axis right x this is much easier to do so i'm going to start by adding actor rotation add actor world rotation just like that and this is really simple to do all we're going to do is we're going to split this direct pin and we're going to drag over this execution our axis value will be going into our delta rotation z but before we do that i always like to add in a low modifier in case this ends up being too slow um i'm going to go ahead and multiply this and that's going to go into our delta rotation z and i'm just going to make a an output value here i'm going to promote this two variable and this is going to be smooth rotation speed is what we're going to call this and so here all we have to do is compile and save that and we can go and modify this smooth rotation speed in order to in order to modify how fast our character is able to move so i'm going to increase this just a little bit i'll set this to maybe five we don't need to be any particularly large number you may even find that one works just fine for you as well but but that's all that we really need to do here now um we don't need to do anything with our x and y z is the only thing we need to worry about since this controls our uh left and right turning x and y will will control our forward and back as well as our left and right tilt so um just keep that in mind we don't need to do anything with those just leave those as zero um if you would like you can also enable sweep and teleport this entirely up to you um i'm gonna leave them both unchecked because there is really no need for either of those so that we're all done here this was really all that we need to do for our smooth rotation it was really that simple our snap rotation however is going to be a little bit more complicated but still not super complicated we're essentially going to be using a kind of modified version of what we have down here so we're going to be doing is first i'm going to run this through a sequence so i'm going to grab a sequence here and there's a couple different ways of doing this i'm going to be doing it in the most simplest way i can possibly come up with we're going to do is we're going to take our axis value and we're going to first see if this is greater than or equal to 0.3 now something to note is this axis value ranges between negative 1 and 1. and typically when you're not touching it assuming you don't have any stick drift or anything that the default value is going to be zero one will be all the way to the right i believe and then negative one will be all the way to left so in order to do this we're simply going to take this this is going to be to check to see if we're holding this all the way to the right so we're going to take this and we're going to branch just like that and we're going to pass that through then zero and what we're going to do is if this does become greater than or equal to 0.3 what we're going to do is we're going to take this and we're going to add an actor world rotation but we're going to do it only once so i'm going to do once just like that and we're going to add actor world rotation just like that split that struck pin and what we're going to do is we're going to make a new float value just for this so i'm going to take this promote this to a variable just like that and let's call this that was weird snap rotation angle is what we'll call this so how whatever value this is is how far we're going to snap our rotation to so i'm going to let's go and compile this and i'll set this to 45 as a good starting point there and in order to reset this we're going to switch this to false in order to reset this so what this will do is it will only snap our rotation once once it becomes greater than or equal to 0.3 and then um once it goes back to zero then it will reset and allow for us to snap that rotation again so that way we're not going 45 degrees so long as our axis value is being held now in order to do the inverse of this go in the opposite direction this is also going to be quite simple i'm just going to take this we're going to check to see this time if it's less than or equal to and this time we're going to do negative 0.3 it's going to be a branch and in this branch we're going to feed in this value and i don't remember if i explained it but this is basically a threshold what we're doing here is we're checking to make sure that our thumb stick is not at zero but it's this this also helps account in case there's any stick drift or anything like that so that way players won't accidentally snap a rotation um i do have a little bit of stick drift on my on my left controller so i this is also partially why i'm doing this is because i know it might accidentally trigger um if i if i don't have this threshold anyways so just keep that in mind you don't have to have this this threshold you can just check to see if it's greater than or equal to zero and it'll be as simple as that if you really want to as well but this is just a nice way to account for any sort of stick drift or anything like that um and then we're just going to do a lot of the same stuff here we're going to pass this through a do once reset on false and then on completed we're going to again add actor world rotation however because we want this to go in the opposite direction we're not going to simply take our snap rotation angle we're going to take this we're going to multiply this value by negative one this will get a this will get the value in the inverse direction and pass that into delta rotation z and that's everything that we need there for our snap and smooth rotation and with that you're all good to go so all of this is everything that you need and with that that's how we set up some very simple snap and smooth rotation that will allow for us to rotate our play space for our vr player and allow for them to move around a lot more freely with that i hope you enjoyed this video if you did be sure to like and subscribe button down below and also i'll give a quick shout out to my patreon supporters you should see over here on the right hand side and with that i'll see you in the next reality
Info
Channel: VR Playground
Views: 7,135
Rating: undefined out of 5
Keywords: VR Playground, VR, Virtual Reality, Game Development, unreal engine 5 tutorial beginner vr, unreal engine virtual reality, unreal engine vr, unreal engine vr tutorial, unreal engine, unreal engine 5, unreal engine 5 vr, ue5 vr, unreal 5 vr, unreal engine 5 vr tutorial, vr development, vr game dev, vr game development, vr rotation, smooth vr player rotation, smooth virtual reality player rotation, snap vr player rotation, snap virtual reality player rotation
Id: oJJ7JFwWdMo
Channel Id: undefined
Length: 13min 3sec (783 seconds)
Published: Fri Feb 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.