UE5 Pressure Plate Puzzle

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another video and today we're going to generate create this puzzle and we're going to generate these plates automatically so let's say we have some kind of a code with three letters boom we have this so our code should be qwe we randomize the code so we need the we need to do like this we need to go q w e and the doors have been opened [Music] so the first thing that we want to do is create a new actor for our new puzzle because it's going to be completely different so right click in the content blueprint class actor i'm going to call mine a bb press puzzle let's open this up and what i want to do is i want to generate the amount of plates automatically so that i don't have to hard code this so that it would generate the plates based on the length of the code so what we're going to do is we're going to go in the construction script and first thing we do is we add a static mesh component like this let's change the static mesh once we select the node of course we can go ahead and add a cube at least in my case this is going to be just a visual representation of the plate so i'm going to select 100 by 100 cube i'm going to right click on the relative transform to give it some kind of values compile and save this go to the viewport and boom i can see my my cube okay but it's too big i want to make this flat so it's a plate so i will lower the scale in the z-axis now if i compile it's flat now the next thing that we need is we need to add a box collision so that we can generate an overlap event once we step on the plate so i'm going to add a box collision like this again split the transform uh let's extend this to 50 by 50 by 50. so it's roughly the same size as the cube but a little bit higher so if we compile this there we go now we have the box collision generated as well but i need to lift this up so in the construction script i'm actually going to go ahead and from the static mesh i'm going to get relative location and i'm going to do plus vector plus vector and i'm going to add 50 units in the z-axis and then that's going to be my relative transform location so if i compile this now the collision looks like this so it doesn't go below but it goes above okay so far so good now the next thing is uh we're going to have multiple instances multiple plates and we want to generate all of them automatically so i'm going to bring this back a bit and i'm going to create a couple of variables first i'm going to create a variable called spacing and this variable is going to be of a float type and this is going to determine the spacing between the actors roughly so i'm going to make mine into like something like 150 because my plates are 100 so i'm going to have it bigger so i have some spacing in between them and then i'm going to have a couple of variables for the input code that we need to provide so basically the order of the presses that we do on these pressure plates so the first variable is going to be the correct code so this is what we want to input now in my case i'm going to be using a string so that i can use letters and numbers or whatever that i want to use now let's say in my case the correct code is going to be qwe like this now we need another variable in which we're going to input these letters so i'm going to call mine input code and i'm going to leave this empty so we're going to slowly populate this variable with the letters until well we reach the correct combination or if if if it's wrong we're going to clear this off and start over all over again now since i don't want the player to just walk from left to right i need to randomize the letters somehow so i'm going to go create another variable and i'm going to create random code and this is again going to be a string and right now i'm going to provide this with just with my hands i'm going to hard code this to be wqe but you can generate this automatically as well but if i'm going to do this then well i'm going to be i'm going to have to guess the code whatever code that i provided in the puzzle i don't i don't want to guess it right now so i'm just going to provide it like it is so let's generate our static meshes based on the amount of input code that we have based on the length of the code so i'm going to grab the correct code variable i'm going to go ahead and check for the length of this string so how many letters we have in it and i'm gonna do minus one because it is going to return us so if we have three letters right now it's going to return us three but i need to go up until two because i want to start from zero rather from one so i'm going to do minus one so that then i could do a loop scroll down to find the regular for loop plug that in plug the loop body and then this value right here can go in the last index like so now all of these actors are going to be piling on top of each other these components and we want to split these apart that's why we created the spacing variable so we're going to go ahead and grab our index value and we're going to multiply this with the spacing value then we can split our relative location for our static mesh and provide this as the x value x-axis so if we go to the viewport compile it now there you go as you can see this is generating us three instances automatically now in the correct code if we provide even more letters this is gonna generate us even more instances if we up bump up the spacing we're gonna have bigger spaces in between as simple as that here we go so so far so good now here comes the somewhat of a harder part which is actually making the overlap events grabbing the input code values and all that stuff so what we're going to do first is first we need to assign the letters to our box collision now the box collision itself can't really store any useful values that we would need so what i'm going to do is i'm going to grab the box collision output and i'm going to set tag i'm going to set component tags like this i'm going to go ahead and make the array and i need to provide now one of the letters so i'm going to grab my random code because this is randomized i don't want to use the correct otherwise it's going to be left to right so we're going to grab our random code and we're going to go ahead and get substring and plug that in and then the length is going to be one so that we would return one letter and we need to have a index so that we know which letter to grab and for that we're going to use the loops index like so so now it's going to generate our code left to right and it's going to be wqe so we're going to need to step on the middle left and then the right plate like this okay so far so good now the last thing left for us to do inside of the construction script is we can drag from the box collision and we can create a overlap event so we need to bind event on component begin overlap so once we overlap the actor we're going to initiate some kind of a code and so we can drag from our event we can go ahead and create an event now this doesn't necessarily create an event but it does trigger something that is going to launch some kind of a code now in my case i'm going to just create a matching function and here is the function so just like if you have already created over overlap events before these all of these inputs are familiar to you these are exactly the same ones you get from the event beacon overlap now what i'm going to do over here is we need to go ahead and first we need to somehow check whether if it's a player now if you know how to create interfaces create an interface and check if it's the player for the sake of the tutorial for now at least i'm going to go ahead and cast to the third person character later we're going to come back and create some interfaces when it comes to some replication stuff and the multiplayer part okay now the next thing we need is we're going to need to provide the the input code so one of the letters that has been assigned to this specific plate so from the overlap component so this is going to be our box collision we can actually get the tags to get component tags and then we can go ahead and get a reference to index 0. and now we need to somehow provide this inside of our input so we need to create a function for that so i'm going to add a new function and i'm going to call this add code this function is going to have a single input uh i'm just going to call this add and this is going to be a string and our task basically is to grab our input code so whatever we have already put in and we want to go ahead and append this new character to it and then we want to go ahead and set our input code so we have added an extra letter to our code now what we need to do next is check if it's uh if it's correct before i check if it's correct though i'm going to check if it's the correct size so we're going to grab our correct code and our input code we're going to grab their lengths so length for one and then we need also a length for the other one and we're going to check if both of those are equal so if both of them have the same amount of characters inside of them and then we're going to do an if to make sure that that is true and then once we have done that the next piece is to actually check if the correct code is equal and i'm going to be using a case insensitive so i can use upper and lower cases so it doesn't matter if you want it's to be case sensitive use equal exactly but i'm going to use case insensitive so i can use both upper and lower upper and lower case letters and then i'm going to check if the correct code is equal to the input code we're going to run a if branch and here once we check whether this is true so if the code does match up we can go ahead and run our open a door and message that we created in the previous videos now we still need to provide a target so which what is the door which is the door that we need to open so i'm going to add a new variable which i'm going to call door and i'm going to make this into a actor type like this compile and save this and plug in the door now if it fails though if the code doesn't match up we want to go ahead and set that our input code has been reset back to empty so that we can try again now if we're going to complete the puzzle in this case it's going to open the door and that's it we are no longer going to be able to interact with this puzzle it's not going to simply work if for some reason you want the code to be placed in multiple times put in multiple times you want to do something like this so that it would reset the input code to empty basically like so okay let's head back into our overlap event overlap function this guy right here and here we're going to run our add code we're going to provide our letter like this compile and save this there we go so now we should be able to test this before we do that though we want to grab our door and we want to make this instance editable so that if we make this instance editable now we can actually bring a instance of this puzzle inside of our level and then in the details under the defaults we can actually select the door so we can pick an actor from scene and this is the door that we want to pick so let's hit play and let's try this out so the combo should be middle left right and there we go the doors have been opened now if we're going to provide an incorrect code let's say we just walk across this you'll see that nothing will happen and then if we provide middle left right the door is gonna go ahead and get opened now one last thing before we end this over here what also is very important and probably very helpful to do would be to grab the correct code make this instance editable as well and same goes for the random code make that instance editable as well because at this point now in the level we should be able to select our puzzle and provide whatever code we want so let's say we do qwerty quality and this is quite a bit too big so let's just do like this and let's say the code is like a random code is like this so the code should be q w e r now there we go okay and that's going to be it for today's video so hope you guys enjoyed it if you like what you see and you have any suggestions questions anything like that leave them down in the comment section below or feel free to join my discount link is down in the description you
Info
Channel: It's Me Bro
Views: 10,263
Rating: undefined out of 5
Keywords: ue5, pickup, pickups, inventory, puzzle, tutorial, easy, overlap, collect, coins, pressure, plate, code
Id: HFarVFT6KgA
Channel Id: undefined
Length: 14min 19sec (859 seconds)
Published: Mon Aug 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.