VR interactables from scratch - Push-button - Unreal Engine 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so let's start at the games launcher and then go to library launch the latest version of the engine for 23:1 and my kids wait for it to load should be rather quick now we go to new project scroll down to VR and virtual reality and let's call it your interact create project few seconds for the editor to fully load and show us the VR template okay let's show the folder content this means the plugins and then inside variety PP with some maps folder we want to go to the motion controller map so we'll open this one okay now that we're here let's import the asset for our button so Rea click on content new folder button import now we scroll to blender cuz I created my bottom in blender and I will hand over this asset to you of course you can try by yourself your button open let's confirm the default just make sure that volume is centimeters import okay give the shaders a moment to compile and should see the button soon the meantime we go again content and just say organize with v8 blueprints folder and inside this folder we right-click look in class actors 1 create a new blueprint actor we call this VP your button takes for a name and now we open it with double-click and we go back to the button folder and 1 & 2 so we shift-click on the two assets and we drag them inside so that they are added automatically to this beach I would like to change names I think we are button base your button button doesn't sound very good so f2 to rename them yes I think it's an extra yeah and then the second one f2 that's also perfect okay so now we have the base blueprint which you see the button have the push part and the base part okay so what we want to do with it let me switch to PowerPoint and basically we're gonna start with the button in its default position and as the hand approaches it and starts to interact with it we detect the begin overlap so as we detect a begin overlap between the hand on the button we start tracking the button the hand will move down direction of the botanist push it and we keep tracking it until the button gets to its final stage as a maximum trouble and at that point from the button we can trigger an event okay the button is being fully pushed open the door to something else now from their own we let the bottle release and go back to its initial State it may also happen that someone doesn't press the button all the way to the end but basically takes the hand away from the button so in that case we also want the button to go back to its initial State both cases so fully pressed or you know end of the overlap the button is back to initial state and it's then ready for the next interaction okay so how we do that now let's go back to our blueprint event graph let's clean it up even though we will need the gained event begin play and tick event later on but nevertheless clean up let's select button here and then on the details panel we scroll down all the way where it says component begin overlap now we click the green plus button and we automatically get the component begin development now we want to the Technic overlap with the hand and the end in this template is copied by motion controller so we cast out of other app turn tasks to the motion controller so in that case we are sure that we are interacting with the hand and we want to store this variable so right click promote to variable ref to see so this is a reference to what happened to motion controller that we are tracking and by the way this is wrong we want to get the motion contour irrelevant sorry about that and that's the one that we want to store about it for so right click promote to variable tracking motion controller let's delete this one we don't need it because we don't want to track the full BP but don't leave the motion controller component which is contained into it okay sorry my bed okay so now that we have a reference to the motion controller that we are tracking let's also keep track of it with a boolean variable so I press down on the pariah liyan we call it is tracking and we drag it out and check it so it's set to true now the next thing that we want to do in this initial step is what two things first of all we want the position of the motion controller so we want to get the board the location of the motion controller and also save it as a variable we call it MC initial location drag down and connect it and we want to do the same with the button so drag out the button same or we get word oops location right click promote arrival but in each location okay so now we have all the initial conditions that we need in order to track you know to understand where we are when the but the begin they develop begins so how do we track the button from the handle well we need event tick first of all let's make sure that we are tracking so we do a branch and use the e striking as control to the branch so only if we are tracking what we do a few things basically we want to take the initial position of the motion controller so tracking MC so I not not initial position but the current position get word with the location and we want to subtract it from its initial position so it's a vector minus vector motion controller initial occation so basically this represents the displacement of the motion controller from the initial location to the current location now what we do is since the button can only move along with axis and its axis if we go to the viewport is its up vector which is the blue one so that is up vector we basically drag the button out get up Vector so we get this app vector and then we use a very handy node which is called project vector onto vector and we basically project them displacement of the hand on the app vector of the button so basically we are only taking the movement of the hand the component of the movement that is along the bottom now I see question popping up is okay can you also use transforms yes you can also use transform so basically you can transform the we're moving on the end into the local space of the button and then take the Z coordinate of that translation and that will work anyway but I find you know working with transforms for beginners is a bit more complicated than working just with vector so we're gonna stick to vectors let's take the length because we want the length of the displacement and just to make sure that it only goes in positive direction we take the ABS done and then we clamp this with a climb float between 0 and its maximum displacement how do you find a maximum displacement so we go back here and by the way let's put the snapping into one for translation so if I drag down maybe wanna go do flow a bit more yeah so minus 7 so I mean 7 units that the displacement at the button can have let's put it back to where this what was sorry so even grass I think this is at 7 so that's the maximum displacement that the button can get before we recognize that it's fully pressed by the way let's turn this into a variety moto variable and we call it Maxie travel Oh displacement that's all fine and by the way this quantity is the current travel of the button so let's also promote this variable current okay so what we do with this varietal is out of true here that's cheap-ass our should keep ourselves organized we want to set the button now to its new position because it's tracking Han so it has to move with the hand and the way to do it is basically to take a vector of the button multiply this vector by the current travel I remember the effectors as forward right doctors these are unit vectors so if we multiply that by the current travel and if we subtract this from the batter initial location we basically have the new location of the button in the worst place and that's where we can set in drag it a bit to the right so out of the button will say that word location and we said the word location to this one okay so basically this is the new word location of the but let's keep it cleaner this is basically where we want to place the button as is following the hand by the way let's turn this into variable as well because me I want to Train want to track it so we'll say you know for any location we need that I think it's useful because that we can use it to compare the current location with the initial location and we can use that example to see if the button has gone back to its initial State but anyway so we have you know the provocation and so this makes the button now slide by the way we could I think already give it a try so let's see what that works at least if the button starts tracking the hand and then no moves with it we have nothing the first you know stop tracking it so basically the hand will be stuck with a button but that's fine or the button stuck with him okay let me try so first of all we have to take our blueprint and place it somewhere in the level let's place it here on the table we can easily get there and test it so I'm going to we our preview mode and grab my motion controllers let's see if we get there let's go to the editor and if we touch the button we should already see that it tracks the hand but you can see that it never stops tracking it nevertheless it it's reacting I think now it went basically into the table [Music] blueprint okay so basically here what happens is we can check now if the button is full pressed and basically we can do it because you know if it's fully pressed and current travel it's better or equal to actually equal to the maximum travel it will not not get past the maximum travel because we will stop tracking them and when that happens there are a few things that we can do I like to create event I like to create a custom event so right click custom event I will call it no fully pressed so basically that's an event that we can use to do something you know the botanist in fully pressed so one neat thing to do when the bottom is fully pressed is to change its color for example to make it glow now to do that let's quickly go back to the button and take the bottom material and that's how we came in from blender which is fine basically we can use OD an emissive color so if I take here and drag out of the color pin and then do a multiply connected to a missive and then you see this B basically this is application factor and what we can do is right click and say promoted parameter and now this B will become a parameter which we call glow so we will give it a default value of 1 which basically makes the button look like death so give me the sack because the material is a compile and if we set it to 10 for example that will make you know the button below now how we can apply this to the button let's go back to our blueprint what on the print and on begin playing begin playing good we're gonna take the button and create a dynamic material instance three dynamic material instance and we are going to use the bottom material as source and element to your spine because this is the only one that we have so compliance safe and we're gonna do next is go back to you know our identity so here wearing the condition that the button was fully pressed by the way here we can call the fully pressed event which we just created so that's where we're gonna go and once the button is too depressed and from there we can take our material instance and by the way in order to be able to operate when a material we need to track it with a variable so let's call it material instant button do it now back down we take the material instance of the button and we color parameter value you remember we call the parameter blue and we said it's volatile damn by the way we could also turn reducing to arrive on right click come out the variable we call it blue intensity in case we want it to glow bit more a bit less okay now if everything is working as expected we should be able to go to our material our button and as we bring it all the way down you see that it glows cool okay now what we don't do yeah is stop the tracking so we said that you know once the button is fully pressed we want to know stop tracking it so we put you know is tracking to false and we also wanted to you know return to its initial state so in order for that to happen so once we're in the event ick you know striking out with slow so we're gonna go onto this branch and we can use another branch and we need another condition which is returning when we need that because we don't want to the user the player to be able to interact with the button while that's returning so we get a new boolean variable called is returning and in here we set it to true so basically now the button is returning to its initial State we track it here and what we can do is basically take the button from the color location whatever it is because we can use that also later when we want to manage this and overlap and bring it back to you know its initial position so one way to do it is to so we have the initial location of the bottom it's here and we have the current location so basically we take the initial location of the button we take which is the target we take the current location which is where the button is right now and we use a nice function called in turn so this is vector interpolation too so basically from the clarification such as this one to the initial location which is our target with you know we need to use a delta time out of tick but I think this is too long to connect so I'm gonna use this thing which is good get the word delta ii same thing we're gonna give out the delta x and the interpolation speed or let's put two and i will see me we can turn this into a variable anyway and call it a blast don't write speed something like that okay so what we do with that is and we have now to update the current location of the button so that you know we can keep doing the winter every time we come back to it and now we save your button set word location make sure connect it to location and basically you know once we do that we want now to detect branch if the current location as we are moving the button in the back to its in its initial location is identical and we use equal exactly for this directors the button initial location then the button is no longer turning so we have basically done it and since it's no longer tracking and no longer returning basically we are back to the initial state where another not tracking and returning can happen okay let's try it out and basically let's see what happens [Music] okay so here we are again it's with our pattern so we move there and press it and as you can see comes back and we can press it again you can press the game we can press it again and it's then comes back to the initial position now what it doesn't do is it doesn't stop blowing and that's basically something that we can make happen interviewer so do we want it to you know stop blowing immediately we want it to for example one thing that we can do is put a little delay here see Europe two seconds and then we can do the same so basically change the government parameter and material instance and bring it back I think was one so that's the mission globe let's see if this time just stops blooming as it should yeah so it glows and then as you see it only glows when it's fully pressed actually I don't like it I think it should blow until it comes back to the initial stage I don't like it I think we can put it you know at the end of the return so basically when it has returned all the way to the top we will stop blowing I think that's very nice so what else is left basically we said earlier that we might want the button she also go back to its initial position when the overlap with their hand stops so someone has not pushed the button all the way to through but you know they move the hands away so they change their mind so basically we can do the same here take the button click on it go back to the details and this time we click on come and on component and overlay okay and what we do is yeah same deal we want it can still motion controller just to make sure that we are dealing with the motion controller and then we take the motion controller out of it so the component okay and we compare it with the column and we are tracking now you see the near and the components of tracking motion controller component and basically we say well if with a branch that is true so we the end overlap comes exactly from the same motion controller we are tracking we stop tracking and trigger return so basically that will then bring us in the same branch that we were in before let me move this down and what ticket here is returning and then we'll bring back the button from the car location all the way to diminish a location and once it's there it whoa well said it you know to stop blowing but it never started blooming and first place here so that whoa no nothing that's okay let's give it a try I think in its returned a bit quicker so now you see that if I take my hand away basically the button goes back to its initial state but you know doesn't glow so there's it's not trigger off for it and actually we have a bug here where the button has taken a new initial state and I know where that comes from we didn't allow another button to go all the way back we interacted with it and create the new burlap while it was not still going back so if we go here go back to our blueprint basically we don't want any overlap to be happening if you know we are still tracking or returning okay so what we're gonna do is move this a bit to the side and we're gonna put the branch in here and I like it's to be flinging this perfect and we say well if you know if we are already tracking or now we are returning basically we don't want to be able to detect you know the the new tracking so basically let's do it the other way around so we say if we're not tracking and we are not returning then it's okay not to start a new tracking while we're tracking already tracking for and we are just returning we don't want new tracking to start so we'll stick to to that basically that's yet the back term will no longer interact in that time span the other thing I want to change is the return speed of the button I think it should be quicker so let's put it to five and let's give it another try so here we are with our button again we face it it's easier let's see click up done click up none click but not all the way it's gone click done click done yeah then you have it of course we can use for example no blueprint to brain communication or you know we could trigger something from that button and one way to do it for example yes to use an event dispatcher or you know we could simply invoke a function from another blueprint and you know have it open a door or opener secret compartment or whatever you might need in your game all right thank you so much I hope this was useful and you know see you in the next tutorial bye
Info
Channel: Marco Ghislanzoni
Views: 9,782
Rating: undefined out of 5
Keywords: vr, tutorial, unreal engine 4, UE4
Id: l9hjb7kt854
Channel Id: undefined
Length: 33min 11sec (1991 seconds)
Published: Tue Feb 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.