How to make VR gun (Unreal Engine VR tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there i'm servants and in this tutorial i will show you how to create vr rifle for your unreal engine vr game i will show you how to reload it change ammo and also how to switch between fire modes you can see it somewhere behind me so let's not waste your time and get to it alright let's get started i'm using vr expansion plugin so if you don't know about that somewhere here is video explaining all that first thing we will do is to find an example in here so in search content let's just put here a gun there we have a gun base so let's duplicate it and call it my gun or something like that let's do just my gun underscore bp and now if you click on this little icon on the left you can put it into content just in the folder of content and now you will probably also want to switch assets so what i have done here is to find some custom guns that i can use these are part of packs so i can't give them to you but you just need to find something similar and make sure that you separate parts that you want to be removable let's open my gun put it in here and the problem that you will probably face is that it won't be rotated correctly so if you just click on that gun let's try to replace it with this thing and you can see as i thought that it's rotated in the wrong way and the thing is that we can't really rotate it in here because if you were to rotate everything else it would completely mess up holding its stuff so but i would recommend you to do is to right click on that assault rifle and export it quickly away so let's export it somewhere put it into blender delete everything else i always like to have blender opened at the same time as unreal engine because it's super easy to go between these two so let's import that and on the thing i will do here is to of course delete these collisions we'll get rid of them later as well in the unreal and let's just rotate it on z axis along 19 degree and i'm not sure if it's 90 or minus 19 but we will see in a moment and now again quickly export fbx selected objects only and in export you can export it to the same file because now back in unreal here we go you can just right click or import a new file and select the same one you can you don't have to reset it let's just ignore that and now if you put it in here now you can see that it was supposed to be -90 and the scale doesn't work that's that sadly enough sometimes happens so quick way to fix that is of course to set this to -19 and with a scale what you can do is to set up here units set it to 0.01 that should do the trick let's try to export it now and if i import it it should hopefully be as i like it that should now hopefully work look at that that's how it is supposed to look like and for some reason it also reseted our materials but i'm not gonna really worry about that it looks just like some bug let's just set here same material all right compile it and now what you have to do is to of course set up our well let's slow down the camera so i don't move around so much let's set up these hands so they fit how we would like it to be all right i'm not gonna play with it too much just something that will represent how it is supposed to look like blah blah something like that let's say not sure if you would have your hand like that but let's ignore that and hopefully you will spend more time and setting it just right all right let's also delete virtual stock and all this text don't worry about that we don't need it compile it as well as this thing and this thing will give us some error we can ignore that not gonna need that probably move that fire collision because a fire location that's a space from which it will fire and we will want to make bullets a bit smaller because right now if you look into event graph it will set them to only half of its size and they are pretty big so let's try about 0.3 you don't have to set it it's just a bonus thing that i would recommend you to do to make it bit more realistic or you will probably want to create your own bullets afterwards alright let's put it in the game and make sure that everything works all right now let's move towards it and grab it and look at that i actually make pretty good holds it should shoot pretty fast if you press trigger you can oh come on you can of course use your second hand all right now to the next part let's move content browser next to each other so you can switch between them by the way that's super handy i would recommend you to apply this in your workflow and what i will do here is to set up system that will let us switch between different fire modes right now it's set just to full auto but i would like to add here a semi and also some single shot to do that we will need something that will help us switch between that so let's add here add component and we will add vr component from the vr expansion plugin and if you scroll completely down there should be a benefits vr dial and as our static mesh right now i will just use dial vr dial up top that's it yep now what we will want to do is to enable dial use snap angle list so let's enable that and adhere a few elements that's basically in which angles it should stop so one will be of course zero which is this one then let's do 90 and 180 that should help and now let's scroll down and put here on dial hit snap angle and before we will actually setup it here let's add here some switcher so right click put here switch on hint and let's add here three variants zero to free and our selection promoter variable and let's call it gun mode and we will connect it after our fire local let's take it here because if you would look at all this logic basically after you press the trigger button in this case event on use it will get to exactly this thing this fire gun local that will start timer which we will use as full auto and start firing right here so on our gun mode 0 i would like to just fire a bullet that means it will shoot only once so fire a blood on on one let's do that let's say three times so fire blood put here short delay 2 0.1 that's maybe too much but you can set it up later let's move it somewhere here and do that like three times and we don't want that and we don't want it to be messy so right click and collapse it just to notes for now all right semi mode all right move that back in here and our second let's connect back to this timer because that's auto you can comment it of course so let's put it c single c semi and we can change this to auto and now on our hot dial what we will do is to put in a branch and make sure that if this is equal to oh no that's not equal equal to zero it will set up our gun mode to zero which means it will shoot on which which means it will shoot only once once you press the trigger now if it's false and it's 19 oh no sorry if this connector is here and now if angle is equal to 90 it will set the gun mode to 1 and again if it's 180 it will set it to 2 which means auto all right and by default make sure it's set to zero wanted to shoot only once we have to do few more things before it will actually work because right now it's pretty hard to grab it so first thing you will do is to click here put it bit more in here a bit more on the side and we should have here something like a priority yeah grip priority and let's make it free gun should be just one right and one more thing if you look at that gun at the mesh of that gun it will have probably pretty bad collision so collision simple collisions yeah and it's way too basic so let's just create new ones collisions of convex collisions and apply that and one last thing that i forgot to manage here we have to enable a dial use angle snap so it will automatically snap to that angle that we want so make sure that this one is enabled right now in vr it should actually work all right if i take it and press the trigger it shoots only once let's snap it to two shoots free at the same time you can see that the delay between them should be a bit shorter you can set it up yourself and if i put it right here it's automatic let's go time to find some school all right now let's get to last part and that's reloading let's create here new blueprint because we want to have that amo as separate blueprint so you can pick it up let it be actor and let's call it ammo underscore bp or maybe i can call it under scroll for all time sake we will have to add here a component it should be static grippable static mesh and let's set it to of course assault rifle ammo or magazine i think it's a proper world and now let's go into my gun bp and what we'll have to do here is to adhere a collision let's it be just box collision and we will have to set it up so it's approximately the same place that you want to have your magazine so don't in this case don't use scale in here i would recommend you to use box extend shape and that's because we will use transform of this collision to set up our ammo so it would kind of mess it up if any changed scale so let's put it approximately here and change our box extend and what you should also do is to change rotation a bit all right so let's scroll down and on component back in overlap let's cast to our new ammo so i'm gonna be in and connect it to other actor and now first thing we want to do is to actually destroy it so destroy actor this one and let's put it a short delay and that's that delay is there simply because sometimes for some reason it doesn't like to destroy stuff and create stuff at the same kick at the same time not sure why that is it's just something that i would recommend you to do so let's do super short something like zero zero five after that then let's create our spawn actor from class and it for the transform let's actually if i forget the location will be enough so let's take that box get world location and connect it in here nsr class of course set up ammo i'll be beam and what you want is to also attach it to a gun so attach actor to actor and apparent actor will be just self so let's take it from here and put here self get reference to self and we will keep wallot starting by putting this a bit longer let's try 0.02 and also let's put here a do once note because we are never too sure if that overlapping is not happening too many times and let's also when we are ready to fix that collision or that wiggling movement you could have seen and go into ammo in your gripper static mesh and in vr grip interface let's put it down and manipulation grip switch to attachment grip both of them and it looks like our physics goes a bit crazy once you do that that's simply because physics from this is quite angry with this so we don't want that we can quickly fix that if we go into my gun vpn and set up here another thing we will have to set set collisions enabled right here let's put it right after that and we don't want to simulate physics we want to use only query which means that you will still be able to grab it but it won't work with physics so take it from here so right right click here promote variable connect it in here and we are going to call it a more ref say reference so we have our mrf so we need to take that mesh so that the get grippable static mesh and let's assign here on grip because once you grip it it was it will be out of the gun which is exactly what we want so compile and set up set it up here and first thing you want to do is to take our set collisions and switch it to physics as well so it will work so it will again interact with floor you can throw it etc because as we all know drawing stuff in vr is super fun let's connect it in here and the next thing will be of course to go right from here and connect it to reset so we can put here another ammo magazine oh no actually two physics only i want collisions enabled for query and physics all right that should help us okay so i managed to made it work for some reason i had to switch it to snap to target in this case and then in your ammo i actually had to change it right here so i put the sma those 90 degrees right here so it's rotated and and i of course change the grip priority here otherwise you would be always picking up a gun uh to do a grip priority right here set to 3 and that should be that let's add here also some sort of ammunition so you really have to reload it so in ammo let's create here variable let's just call it ammo and we will set it to integer and let's set it to i don't know birthday one and in my gun let's create the same one so call it ammo gun i i changed the name just so it's easier to work with so what we will do here in our cast to ammo you want to say set i'm organ do and let's actually do it after the two once just to be sure connect it in here from our ammo in here so get ammo set it in here and connect it as it was and now we will also want to do once you shoot fire blood right here let's start by taking some ammo away so let's move all this back and take your ammo gun get it set it to minus one so integer minus integer and set it as new gun so set oh we have to take it from here i'm again and set then let's put it a branch and if it's less than zero you can shoot or less than or equal to so less or equal to zero you can shoot oh if it's false actually if it's true then it wouldn't make sense right and we can actually show it to players somehow so let's put it a text scale it down let's do 0.2 times 0.2 set it to center and let's do it in construction script you want to set text make sure it's set text and not set text render and we'll set it to ammo gun so right now it should be zero and then of course let's come here ctrl c and do it every time you shoot so let's put it here just to quickly explain it once you put magazine in your gun it will set our gun to the amount that is in that ammunition which means in this case if it's brand new one it should be right here 31 i just put a number out of my head what i had because i have no idea how much ammo these guns have and then every time you pull the trigger and shoot something it will take one from it and until it will be zero once it will be zero it won't shoot anymore and it will be of course updating the text and show you how much ammunition you still have left in here let's see if it actually works all right let's take this thing i can shoot that's good let's put it ammo and it didn't update it but that's fine it still should be able to shoot i just didn't put that update once you put the magazine in that we will have to fix that let's put it in zero two only one all right now let's put that thing away and if i put it back how it reset it that's interesting that shouldn't how i know why they just did it we just also have to change it in our magazine let's put it away let's start by setting it once you overlap it so let's take our set text in here and set it right after you set the ammo so move that back and put it in here later on you should of course collapse all this to function and stuff like that that's more of optimalization thing i will probably make quite a lot of videos about optimization in the future and that's something i'm looking into right now quite a lot all right and one more thing we will have to set it in here to minus one so it won't stop on zero but on minus one and we have two options right now we can set the same amount of ammo as we are setting here in our other object but we have already a system that that we work with once you let go of it once you actually pick it up and then pull out of the gun so we can set it right at this moment so let's take our mrf and set ammo and this time around we will set it right in the opposite way we will set our ammo gun to our ammo all right that should do the trick go down zero throw it away and run there we go that looks great i think there is one more thing that it will still shoot even if you put it away because it will have still set the variables so what we can do with that is to put it a quick bench in my gun we have to make sure that it's in there so just simply put here variable to do after that once let's move it back and let's put it variable let's set let's set it to can shoot set it to true and then set it to false in here and put here quickly just another branch and can shoot if it's true it can shoot if it's not it can't of course by default it should be false and will be set to true once you put the magazine in alright that should be it alright that should be everything for this tutorial i hope that you learned something if you want project files for this they are on my patreon and huge thank you to everyone who is already supporting me on patreon so that's about it see you around and serve fancy out
Info
Channel: Sir_Fansi Gamedev
Views: 1,952
Rating: undefined out of 5
Keywords: unreal engine vr gun tutorial, unreal engine 4 vr gun tutorial, unreal engine 4 vr tutorial, unreal engine 4 vr tutorial beginner, unreal engine vr, unreal engine vr game tutorial, unreal vr, unreal vr development tutorial, unreal vr tutorial, how to make gun in vr, Unreal engine VR tutorial, Unreal VR gun, unreal engine vr tutorial, ue4 vr tutorial, vr expansion plugin ue4, unreal engine 4 vr, How to make VR gun (Unreal Engine VR tutorial), unreal engine VR gun tutorial
Id: q2nRFlH_ytc
Channel Id: undefined
Length: 20min 1sec (1201 seconds)
Published: Fri Oct 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.