How To Make Pong In Unreal Engine 5 Blueprint Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this video I'm going to show you how to create pong inside unal engine from a completely blank project in this video you'll learn how to create a full game and how to set up things like input enemy Ai and more and if you want the complete project files for this pong game check out my website you can get them there hello to get started I'm in the unreal project browser and if we just go to the game section and for the template make sure to select the blank one we're going to be creating our pingpong game from a completely blank project for the project name I'm just going to call this pingpong and then I'll click create so it's loaded up my unal engine project and normally when working in unal engine I like to just go to the content drawer and just dock it in the layout that way I can basically um access all the project files in my project now the first thing we're going to do is create a new level for our pingpong game so inside of the content folder I'm just going to right click create a new folder and I'll just call this Maps then if I just go up to the top where it says file I'll click new level and I'm just going to select basic and then go create then we just want to save this level so if we click the save icon it will ask us where we want to save the level and I'll just save it inside of the map folder that I just made and I'm just going to call this level we can save this now the next thing we're going to do is create a paddle that our player character can control so so if we just go to our content folder right click again and we're going to create a new folder and this time we're going to call it blueprints then we just want to open it up and we're going to create a blueprint to do this we can just right click go blueprint class and select a porn so a porn is basically an actor that can be possessed and received input from a controller so we want to select porn and we're just want to call this our paddle blueprint double click and open this up so we're going to design a paddle character to do this we can just go to our components Tab and go add and just select a cube then with the cube selected if we go here where it says select and scale objects just kind of change its scale so it kind of looks like a paddle so I'm just making mine a bit thicker and a bit thinner and I think this looks good then we also just want to add a camera to our paddle blueprint so the camera is going to be how we see our character so we just go add and then look for um camera with this camera if we just um select it and then go to select and translate objects just move this camera up a bit and also just rotate it so it's facing down on the um paddle so I'm just going to rotate it like this and that is good we can compile this and we're going to make it so we start the game off as our paddle character so to do this we we need to create a new game mode and in that game mode we can choose the starting character for our game so to create a new game mode we can just right click and code blueprint class and we just want to select game mode base so this basically allows us to configure the rules that our game will kind of have I'm just going to call this my ping pong game mode then if we just open this up and if we just go here where it says default porn class this is to be the starting character in this game mode we just want to change this to be the paddle blueprint that we just made we can then just compile this close this and if we just go over to window and select World settings it's going to ask us what game mode we want to have for this level if we just drag our ping pong game mode and then in the level you're going to see this player start this is going to be where in the world our player character starts if I just click this um play button I should start the game as um the paddle character and we can see my camera is very close so I'm actually going to move it back a bit I just open up my um paddle blueprint and I'll just select my um camera and let's just move it so it's a bit further away we can compile this and now I go play we can see my simple paddle character the next thing we're going to do is add some controls so that we can actually move and play around as the paddle to set this up if we go over to the content folder just right click and create a new folder and just call this input then if we double click and head inside here right click and then go input and select input mapping context this will basically store all of the controls that we're going to have inside of our game let's just call this the Ping pongor input mapping context the next thing we're going to do is create a control to move our player character so to do this we can just right click cck again go input and this time select input action call this the move input action double click and open this up and for the value type change this to be an AIS 1D float you'll see what this does in a second save this and then we want to head back to the ping pong input mapping context and just double click and open it up we want to go to add new mapping and just select the move input action so the next thing we're going to do is B basically assign a certain button to perform the move input action so whenever we want our player character to move I'm going to make them either press the up or the down button and this will make them move so if we just go here to the keyboard icon if we just select it and look call the up button so when my player presses the up button it'll perform the move imp action we also want to make it so if the player presses the down button they can move the character so we just go add new um control binding and this time look for down for this one we're going to go to modifiers and go add element and just select the negate modifier you'll see what this does in a second the next thing we need to do is just add this um input mapping context to our paddle so the player character can actually um use the controls if we just go back to our paddle blueprint go over to the event graph and we want to go to event begin play so I don't have mine so if I just right click and look for event begin play this will basically fire as soon as our game starts and the first thing we're going to do is add our controls to the game to do this we can just right click and look for get controller then from here we can drag off and look for cost to player controller connect this into here then just drag off as player controller and look for enhanced input local player subsystem we just want to drag off here and look for is valid and this will just check to see that we have a valid controller for our player by default we will then once we've added this we can just drag off here and look for add mapping context and we just want to select the ping pong input mapping context and that will add the controls that we set up here next in some free space if we just right click and look for the move input action so whenever my player presses either the up or the down button this trigger node is going to fire and we're going to basically make it move our paddle so to do this we can just drag off here and look for add local offset and we're going to look for add local offset Cube we going to be moving our Cube now we're only going to move our cube in One Direction if I go over to the viewport and just select this um Cube and go to select and translate we're going to be moving our cube in the y- axis so this green one here we'll move it either up or down just make sure that you um changed the location of yours back to zero if you moved it around if we we head over to the m graph on this add local offset we can just right click here and look for split structure pin we're only going to be moving it in the y- AIS now if you remember earlier when we set up the move inut action I may just change the value type to be axis 1D float because we did that we should see this little green um action value here whenever the player presses the up button this value is going to be one if I just head back to the ping pong input map and context for the down button we added this negate modifier so whenever the player presses the um down button because we added the negate modifier this value will be negative so if we just drag off here we want to multiply this and we need to multiply this by a certain value if we just right click and PR this to a variable and call this player speed so this variable will control our player speed just compile this and for now let's just make it 10 and connect this into here so again if I press the up button this value will be one and then 1 * 10 this will basically positively move my character in The y- AIS if my player presses the down button this value will be negative 1 and this will cause my player to basically move in the opposite direction in the y- axis we can test this out if I just go compile so you close this and now if I play my game when I press the up button okay so when I press the up button I move down and when I press the down button I move up that's probably because I've rotated my camera the wrong way if I just hit head back to my paddle blueprint and go over to the viewport let's just select the um camera and just rotate it we just want to make sure that our camera has a value of um zero in the xaxis that's the um correct way so I think mine was um just rotated incorrectly so now if I go compile save and I play my game when I press the up button my padn moves up when I press the down button my padn moves down so with this we've created a simple patter that my player can move up and down hello so the next thing we're going to do is create a ball that the player can play pingpong with to get started if we just go back to our blueprints folder right click and go blueprint class this time just select an actor and just call this the bull blueprint double click and open this up and then we just want to go to components and go add and just add a sphere and for the sphere we want it to simulate physics now if I just go compile and close this when I um place this ball into my level it should um fall down and start simulating physics this is good the next thing we want to do is just make it so our ball is locked in the z-axis this will prevent it from falling down so if we just select the sphere go to details and scroll down and just check lock position then go compile this should make it so our ball can no longer fall down it should just be in the air nice now the next thing we're going to do is add some impulses to our ball which will force it to move so if we just go over back to our ball blueprint and go over to the event graph and event play we just want to drag in off here drag off here and look for add impulse connect from event begin play into here and just right click here on the impulse and look for a split structure pin and we want to add an Impulse to our ball in the x-axis and we're going to make that impulse a negative value that way it moves towards our player character so we just open up the bull blueprint and here in the X let's just type in minus th000 and also make sure to check Val change if we don't check this then the impulse force is not going to be that great so make sure to do that then if we just go compile close this and if I go play my ball should um go towards the right and then hit my paddle nice so I'm just going to move my ball a bit further and we can see that again and nice the next thing we're going to do is fix our Ball's bounciness when I click the play button when my ball hits its paddle it kind of loses its velocity when it hits the paddle we want to make it so when the ball hits the paddle it still kind of keeps its velocity and just reflects back so in order to do that we can create a material so we just go over to the content folder I'm going to right click and create a new folder and I'll just call this material then we just want to right click and go to physics and set a physics material and just select phys material go select and we can just call this bounce material double click and open this up and for the friction we going to make this zero so this is going to be how much friction this object has when it hits something we want to make this zero and also make sure that the static friction is zero the next setting we want to change is the restitution this basically reflects the bounciness of a surface basically if this is basically one when it hit something it's going to leave with the same bounciness that it hit with if this is a lower value then it's going to kind of lose its bounciness when it hits something so we want to make this one as well we can also just kind of hover over each um setting to kind of see what it does we can save this then we just want to go over to our um all blueprint and just select the sphere scroll down and for the physics material override just change this to be the bounce mat that we just made so the bounce material we can compile this and save it and then we also want to just apply this to our paddle so I'm going to select my C here and for the physics material I'm going to give the bouncy um material that I just made we can compile and save this and now I good play when my ball basically um hits my paddle you can see the the ball when it hit the paddle it kind of didn't lose any of its bounciness that's exactly what we were aiming for okay so the next thing we're going to do is add a couple of walls to our level if we just go here where it says quickly add things to the project look for some shapes and then select a cube we just want to move this down and then I'm just going to go to select and scale objects with the cube selected we can also just press the R button to um switch to that shortcut to scale objects and I'm just going to scale and add some walls so I'm going to add a wall here and then I'm just going to press alt and select this um Cube that will allow me to duplicate it so now I basically have some walls and for the walls also make sure to give them the physics material so the bounce material that we made earlier make sure that both of these and walls have this and then I'm just going to kind of adjust um my walls so they kind of fit in the camera so I'm just going to do that now okay nice now I've added some walls to my um game the next thing we're going to do is add an AI which we can play Pong with to get started if we just select the paddle blueprint right click on it and go duplicate this will basically duplicate that blueprint and we can just call this our aior blueprint double click and open this up and we can just delete all of the ndes inside of here and also just select the camera and delete it as we don't need it for the AI so the way our AI is going to work is we're going to make it to a basically follow the pool to do this if we just right click and look for the event tick node so basically the way event tick will work is every single frame it will run this um node and event tick will make it follow the pool to do this we can just drag off here and look for set actor location and we're going to make it so our AI will basically move from the location that it's at to the location where the ball is at to do this we can just right click and look for V inter to constant what this node will do is it'll basically take in a current Vector value so we're going to basically get our ai's location and then we'll make it move towards that Target value so we'll get our Ball's location and we'll make our AI move from its current value to the Target value how faster we do this we basically depend on these two variables here Delta time and Inter tur speed for the Delta time we can just connect Delta seconds into here and for then tur speed like I said this will be how fast it takes the um AI to move from its current um location to its Target location so for the current value we can just right click and let's for get actor location and connect this into here for the Target value if we just create a new variable and just call this ball reference for the variable type we're going to look for the all blueprint that we made earlier and just select object reference then we just want to drag in the B reference and just drag off here and look for get sphere so if we just scroll down and we want this one so inside of our um ball blueprint we basically want to get the location of the sphere then if we just drag off here and let go get World location now we only want to um basically make our AI move to the ball's location in the y- axis so only in this screen axis here we don't want it to move in the Z or the X here I'm just going to change this back to zero so for this if we just right click on it and look for split structure pin and for the Target here if we just right click on it and go split structure pin and just connect Y into y then we just want to copy this get actor location paste it so crl c contrl v then if we just right click here and split the structure pin and connect X into x and z into Z that way our AI will basically maintain the locations that it has in the X and the z-axis for the interp speed if we just right click click and promot this to a variable and just call this AI speed we can compile this and for now let's just make this 500 we can play around with this later then we just want to connect this return value into the new location and event tick it'll kind of make our AI move towards the pool if I just go compile close this and then drag my AI somewhere into my um level initially this is going to fail so if I just click play when I stop playing my game we can see I get these error messages saying blueprint runtime error access none trying to read the property B reference basically we're getting an error because my AI is failing to um get an accurate reference to whatever the ball is so in order to get an accurate reference to the ball what we can do is just go back to our ball blueprint and event begin play we just want to drag off here and look for the get actor of class mode so this one get actor of class and the actor we want to get is the AI blueprint so I'll look for AI blueprint so what this node will do is it'll basically get the first actor with this class we only have one AI on our level so this will basically just get the first AI in our level and create a reference to it we just want to right click and promote this to a variable and call this our AI reference connect this into here and then we you just want to drag off this AI reference and look for set all reference and drag off here and look for self and then connect this into here so basically telling the AI reference that this ball wants to be its ball reference we can just compile this go back to our AI blueprint and also on event tick if we just drag in the B reference get it and just drag off here and look for is valid and just connect this into here and is valid into here this will also prevent the error message so only if we have a valid reference to our ball will basically make our AI move towards it okay nice we can test this out so I'm just going to go compile close this and let me just move my ball so it kind of starts up a bit and the AI should move towards it nice so let's see if I can just hit the ball and the AI will kind of move back okay so I kind of hit it like um down and as we can see the AI kind of hit it down as well although um seems there a couple problems I don't think I made my walls high enough so I'm just going to make them a bit thicker and then also another problem both the player and the AI can kind of um face through the walls so if we just go back to our paddle blueprint and we just want to go to the bit where we add the local offset and just check this sweet box this will basically check to see if our paddle basically overlap something when it's trying to move with the the sweet box enabled it will kind of block our um paddle from moving and if we also just compile this then go over to the AI blueprint make sure to just check the sweet box here as well but for this to work we also just need to drag our Cube into the default scene route so that it's the um main component then we just go compile this will prevent both our player and our um AI from moving past our walls the next thing we're going to do is make it so every time the player or the AI hits the ball the ball will actually get slightly faster even though we set it so the ball will have as little friction and as much bounciness as possible sometimes if we do hit the ball from like certain angles it will actually become slower so in order to make the ball become faster over time if we just open up our ball blueprint and we just want to right click and look for the event hit node so the way this will work is every time our ball hits something it will kind of fire this node but for this to work just make sure that the sphere is selected and we scroll down and just make sure that you've selected simulate generate hit events so make sure that this is checked so event hit every time our ball hit something like a wall or the player we'll make it go a bit faster so if we just create a new variable and just call this all speed for this variable type change it to be a float and just compile this and for the time being just make this a th000 because that is um the speed that we basically give our for at the start and when we hit something we just want to get our bull speed drag off here and look for ADD and for the time being let's just add 30 and then we just want to trackon our B speed again set it and just connect this into here so every time our ball hits something we make the ball speed a bit faster to actually apply this to our ball if we drag in the um Sphere track off here and look for get physics linear velocity this will basically get the um velocity of our ball and we just want to drag off this return value and look for clamp and we want to look for this one clamp Vector size this will basically make it so our ball will have a velocity which has to be between this minimum value and this max value for the value we can just drag in our ball speed get it and connect it into here then we just want to drag off our sphere again and look for set physics linear velocity and just connect this into here and this into here then if I also just um copy these two notes here so I'll go contrl C and crl V connect this into here and then I'm just going to drag off here and look for the print string node and connect this into here and now if I just go compile and play whoops so if I just go play again every time I hit the ball we should see it gets faster so we can see it's 1090 and in the X then it's 11,20 in the X and basically slowly but surely over time the ball becomes faster and uh faster nice the next thing we're going to do is create a score system so that player one or the AI can score some points if I just go back to my ball blueprint though I'm just going to delete this print string and then compile this okay so to display the score that the player and the AI have we're going to create a user interface which will show this so so inside of my blueprint folder I'm just going to right click go user interface select a widget blueprint and I'll select user widget and I'm just going to call this score widget blpr I will open this up and if we just go to the pallet and look for a canvas panel and just drag this somewhere into the hierarchy then in the pallet let's look for a horizontal box and just drag this somewhere into the center here just make it kind of this length and just select it and for the anchor just anchor it to the center of the screen then look for a text and drag two pieces of text into the horizontal box for this first text just select it then go to padding and go to right and just give this a padding of say 500 so as you can see the padding is kind of pushing um this text away from it so we want there to be a bit of a gap between the um AI score and the player score and I'm also just going to select both of these text box and make them say zero and we just want to go to font and make them a bit bigger so it's just a bit easier to see so maybe 100 will be good and I'll also just increase the padding to 700 I think okay nice we can just um compile this and the next thing we're going to do is kind of to make it so this score will basically appear on the player screen so if I just close this and I'm going to go over to my paddle blueprint and after I set up my controls if we just drag off here and for create widget and the widget we'll create is going to be the score we just want to right click on this return value here and let's just call this our score HUD and then we just want to drag off here and up for add to viewport and then just go compile and this will basically add that um HUD to our view nice the next thing we're going to do is set up some goals and when the ball basically crosses one of the goals either player will get a score so I'm just going to right click and go create new blueprint class let's create an actor and let's just call this the goore blueprint we can open it up and and for this if we just go add and we just want to look for a box collision and just Scala in the Y AIS compile this and then we want to go over to the vent graph make sure that the box is selected and if we just scroll down and go to on component we can overlap if this ever overlaps the um ball we want to destroy the ball and then basically increase one of the players scores so when this overlaps the ball if we just drag off other actor and look for cost to ball blueprint then as the ball blueprint we just want to drag off here and up for destroy actor and then this should destroy the ball let's just test that everything is working because we're going to kind of um communicate with a lot of different systems so I'm just going to go compile close this and then I'm going to add a goal here and I'm just going to expand it cuz I think I made mine a bit too small and then let's also just add a goal here and I'm just going to move it so the ball starts up here and if we just go play okay so my ball was destroyed when it um overla that invisible goal I'm just going to move my camera up a bit so we can see that again okay so just make sure that it's destroying your ball so when this happens we want to basically give the AI a score so if we head back over to our score widget blueprint and go over to the graph we want to create two variables the first one we're going to call player one score and for this variable change it to be an integer so an integer is a whole number then if we just create another variable and call this player to score and then we just want to right click in this event graph in some free space just right click and call add custom event and call this update player one score and when this happens we just want to drag in player one score get it drag off here and look for increment in this will basically increase the value of this by one then we'll do the same for um player two let's right click and create another custom event so look for add custom event and I'll call this update player 2 score I will drag in the player two score get it and just drag off here and look for increment int and connect this into here then if I just go over to the designer I'm just going to select this um text here and we can just go bind and we can bind this to um player 2 score so player 2 is the AI so I'm just going to to select this then if we select this text here we going to go bind and bind this to play one score we can then compile this then if I just go back to my gold blueprint we want to create a new variable and just call this player one go and I'll add a question mark and make sure that this is instance editable and Expos on more and you'll see why we do this in just a second after we destroy our ball we want to drag off here and look for branch and we want to check to see if this was player one's go if this is true then what we're going to do is increase player two score by one if this is false then we're going to increase player one score by one and that means they scored but to do this we need to get a reference to the um score wiet blueprint so to get that reference inside of this gold blueprint on event begin play what we can do is get a reference to our um paddle that we're playing the game as to do this we can just right click and look for get player form this will basically get the porn actor that the player is playing the game as and this is going to be the paddle blueprint so because of this we can drag off this return value and look for cost to paddle blueprint then we can just prmit this to a variable so we can just call this our paddle reference compile this and then if a ball goes in player one's goal we can just drag in our P of reference and get the um score hard variable that we made inside of them and then from here we can call the update player two event and this will basically update player two score and then I'm just going to copy these two notes Here If this is false that means player one has scored so we can just drag off here and call the update player one score and connect this into false so now if I just go compile so now if we just close this and just select player ones go here and just make sure to check this Ral here so that we know that this is player one's goal so make sure that we have a check here and then for this one it does not need to be checked as that's player two's go okay so now if ible to just play my game when the ball goes there we can see the AI gets one point and let me try and score one point against the AI so I'm just going to temporarily give it a very horrible speed of one and then I'm just going to move it to the left there and let's say I um score a goal I should get one point okay nice so with that we set up a simple point system the next thing we're going to do is make it so when our ball is destroyed another ball is spawned in in its place so to do this if we just right click and create a new blueprint class just select an actor and just call this the all spawner blueprint open this up and if we just go over to the event graph we want to right click and for add custom event and just call this spawn ball when we call this event we just from Dr off here and look for spawn actor from class and the actor we're going to spawn is going to be the ball blueprint and where we're going to spawn it we can just right click and for get actor transform and connect this into here then event begin Play We also just want to call this spawn or custom event we can compile this and we just want to close this and then go over to our bu blueprint and just create a new variable and just call this the B spawner reference change this variable type to be the B spawner reference and we want it to be an object reference and just make this instance editable and expose one more compile this then head back to the ball spawner blueprint then we just want to right click on this node and click refresh nodes because we made um the ball spawn reference inst editable and exposion spawn we can control the um value of this variable when we basically spawn it in and we just want to drag off here and look for self so that way when we spawn a ball we have a reference to the um ball spawner now if we head back to our ball blueprint we can just right click and look for event destroyed and event destroyed we can drag in our B spawn reference and then we can just call the spawn ball and this should spawn in another ball so we can just compile this and let's test that everything is working so I'm just going to delete my ball and instead I'm going going to drag in a ball spner and I'll just click play so when my ball is destroyed we can see it spawns in another ball the next thing we're going to do is make it so the ball will switch the side that spawns the ball in every time it's destroyed so first it'll spawn in on my player side then it'll spawn in on my AI side so as you do this if we just open up the ball blueprint and we just want to go here to event begin play before we add this impulse we just want to create a new variable and just call it switch and make this variable type A Boolean make it instance editable and expose on spawn as well and we just want to drag it in and for get switch drag off here and for Branch if this is false then we're just going to spawn our ball with an Impulse ofus th000 if it's true however we can just copy this and we're going to spawn our ball with an Impulse of just a th000 also just make sure to select the sphere and make this the target we can compile this then if we go back to our ball spawner before we spawn our ball we just want to drag off here and look for the flip flop node so the way the flip flop node will work is first it will do a and then it'll do B so first we just want to spawn our ball just right click here and go refresh nodes we want to make sure that this is left unchecked then if we just copy all of these nodes contrl C and contrl V then the second time the B is spawned we want to just make sure that the switch variable is checked we can just compile this and then let's test this out so if I go play first it fors the ball on my side then the AI side so it's fair and then one more thing I want to do I'm just going to move my ball to the center of the screen my ball spawner sorry and then I also want The Bard to basically kind of have a random velocity in the um y AIS so I'm just going to right click and up for random integer in range and I'm going to make the minimum value minus 360 and the max value 360 and I'm just going to connect this into y this will convert the integer into a float and then I'm just going to copy this and paste this here that way the ball will not basically spawn directly in the center it may have a variant towards the left or the right so now if I click play we can see the ball kind of spawned in at a slight angle oh and it looks like I also forgot to give my AI speed back so I'm just going to make this sorry it was 500 yep 500 okay nice so with this we have set up a ball spawning system hello the next thing we're going to do do is make it so either player one or the AI will win the game so if I just open up my um score widget blueprint and I'm just going to go to the pallet and look for some text and I'm just going to drag this text and I'm just going to place it here and we just want to Anchor it to um the top of our screen and make sure that this is variable checked and just call this the win text and for the size of it let's just make it 60 we then just want to go over to our graph and if player one or players to score ever equals 10 that means they've won the game so if I just drag off here and check to see if this ever is equal to 10 then we are going to have a branch and we are just going to drag in the wind text and look for set text and we want this one set text text and just make this say player one wins and connect true to here we can just copy all of these nodes and connect this into here and then one more thing we just go back to the designer select this text and in the search look for visibility and make sure that this is hidden so only when the player wins we will show this text so then after set that text if we just drag it in again whoops we can actually just drag it off here and then look for set visibility and just set it so it's visible then I'll just copy this and do the same here and then to stop the game from basically moving about we can just drag off here and look for set game paused just check this I will copy this and then this will basically pause my game okay for testing purposes I'm just going to make this one oh and sorry my bad for this one we want to say player two wins so yeah if player two score ever equals this we want it to say player two wins so let's just go compile play and test this out so I'm just going to let the AI win then it says player two wins or you can make it say AI wins so with this we basically set it up so either player one or the AI can win the game the next thing we're going to do is kind of change the design of our level right now this doesn't really look like the classic pong game although there are some tricks we can do to kind of make our game look like a classic pong game so the first thing I'm going to do is just select my camera and right now this projection mode is perspective if we change this to be orthographic it's going to change it so everything is flat kind of like a flat 2D camera we can change how Zoomed In It Is by changing the autho width so the further away this is zoomed out the um further way the camera is going to be so if I just go play now everything is is flat the next thing I want to do is change the Shadows I don't really like how my paddle and the um ball have shadows so to fix this if we just go to our outlier Tab and look for the directional light then in the search if you look for cast Shadow and just make sure this is unchecked this will make it so our objects no longer cast The Shadow so the next thing I'm going to do is change the um background if we just go to our um materials folder right click and create a new material and just call this blackcore mat double click and open this up right click and look for constant 3 vector and we can just connect this into the base color here double click here and you can change the color of what you want this to be I want this to just be black though we can just click apply to save the changes to our material then just drag this into our level or you can just select it and change the material here now now if I click the play button it kind of looks a bit weird and that's because lighting is affecting our material if I were to just go back to my material select it and change the shading model to be unlit this will make it so my material no longer basically receive light so I'm just going to apply this and the lighting will no longer basically affect the material we can also apply it to um our white material but right now I think it doesn't look too bad so you can also make the um material that the um pong and the ball use and unlit material but I think it's fine for now also you may have notied designing our level is kind of hard and it looks kind of ugly with um this lighting so what we can do is change the way that we can view our level if we go here and change it to be unlit it's going to show us how our level looks with no light there are also other view modes so maybe we want wireframe but we can just change this to be unlet it makes it a bit easier I think but it depends on you so now if I click my play button this is how my game looks nice I may need to move my um paddles a bit back but I think this is looking pretty uh good so far and then one more thing I'm going to do just for um visual flare is add a couple of dotted lines going between these two paddles so I am just going to go here quickly add things to the project and I'm just going to go shapes and select a cube let's move it down and for these let's just make it so they have no Collision so if you scroll down and for Collision presets make it have no collision and I'm just going to make this kind of like that and then I'm just going to create a couple of these and I'll make them display down the center of my game okay so I added some um dotted lines just to have that classic pong effect and I think it's looking a bit better oh and one more thing so I may kind of just change the wi um text color so it's a bit clearer to see and I also just need to basically um change it so they need 10 points to win so let me not forget to do that and then I will change this to be red let's compile this okay the next thing I'm going to do is add a simple sound effect to my game which will basically play whenever the ball is hit so we just go to our content folder create a new folder and just call this sounds head inside here and then I found this ping pong sound effect I'll make sure to leave on link to the sound effect somewhere in the description of this video it sounds like this and if we just go over to the um ball blueprint whenever we um hit it we want to play that sound sound so we just look for play sound at location and then select that um ping pong sound and for the location we can just right click and for get actor location and just connect this into here and if we go compile play whenever I hit the ball it plays that sound also one more thing you may notice when you click the game you need to click the mouse button in order to to start controlling the character in order to make it so we start playing our game instantly just head over to the paddle blueprint and event begin play we just want to right click and look for set input mode game only connect this into here and then just right click and look for get player controller and connect this into here then if we go compile and we play our game we'll instantly start playing our game then finally let's go over how to add a main menu to our um game so I'm just going to right click go user interface select a widget blueprint select user widget and I'll just call this my main menu widget blueprint I will open this up and in the pette if I look for a canvas panel and just drag this in here then I'm going to look for some text I will anchor this to the top of my screen and I'm just going to make this text say pong I will make this 120 so it's a bit bigger and then in the pallet if we look for a vertical box I will anchor this to the center of my screen and then I'm going to look for a button and I'm going to drag two of these inside of the vertical box then then I'm going to look for some text and place a text in each button for this first text I'm going to make it say play for the second text I'm going to make it say quit and I'm going to select both of these texts and make them a bit bigger and I'll add some padding to the first button so let's add a padding of 200 actually I'll make it 100 okay and then we just want to select both of these buttons and make sure this is variable checked and just call this the play button and we can call this the quit button so I'll make sure it is available and call the quit button when the quit button is clicked so if we scroll down go to events and go on clicked onclicked we just want to drop off here for quit game this will quit our game and then in the designer when we click the play button when we click it we can just drag off here and look for open level by object reference and the level we want to open is going to be the um I can't remember what we called it I think we just called it level let me just double check yeah so it's called level and then if we just compile this we're going to create a new level for our main menu so I'm just going to save this go file new level and select an empty level create and in this level if we just go open level blueprint event we can play we want to create a widget and that widget is going to be the main menu and then we will add this to the viewport we will compile it and then our main menu also needs a game mode but this can be very simple so we can just right click go blueprint class and select game mode and just call this the main menu game mode it doesn't need a character so if we just go to world settings and we can just drag this here and then one more thing with our main menu if we just head back to it we want it so our player will be able to basically click and interact with the main menu so to do this we want to make sure that the mouse cursor is showing so if we just right click and it we get player controller and just drag off here and look for set show mouse cursor make sure this is checked this is basically making so we can see the mouse cursor and then we just want to drag off here and it for set input UI only this will make it so we can interact with the main menu and now if I go compile and play when I'm in this level if I click quit it will close my game but if I click play it will take me to my pong nice and then one more thing if we just go back to our um wi screen then if we go back to the score wiet blueprint when the game is over let's give the player the option to go back to the main menu or to just quit the game so I'm just going to go to my pette and look for a vertical box I will anchor this to the middle and to save time I can just go to my main menu and I can just copy both of these buttons with the text so I've just selected everything and then inside here if I just press contrl V I'll basically paste that inside of here and I'm actually just going to make this a retry instead of quit cuz yeah and then um if I just select this quit but when we click it we want to um quit the game and when I click this retry button we want to go here open level by object reference and we want to open up the level again and then we also want to just select this vertical box make it a variable and just call this um buttons and we want to make sure that this is not visible so let's make sure that this is hidden when it's initially um on the screen and then only when one player wins we will make this visible so I'll just tracking the buttons here and before we B the game let's just look for set visibility actually we can just connect the buttons into here and I will just also drag in the buttons again and connect it into here and then one more thing when we basically show buttons I want my player to be able to interact with them so I'm just going to go back to my main menu and copy these notes here and I'm just going to paste them before we pause our game and then I will just compile that so when the player so when either player wins this will appear so I'm just going to change this to be one just so I can test it so let's say player two wins then I can retry or quit maybe I can change the color of these buttons as they're kind of a bit off but um hopefully you understand the code and the logic behind it and then we just want to save this and we just want to call this our main menu level and just save this hello the next thing we're going to cover is how to explore and share the game if we just go over here where it says edit and go to Project settings go to maps and modes and we want to go to the game default map this is going to be the first map the player sent to when they open our exported game we want to change this to be the main menu then if we go over to the editor startup map this is going to be the map we are taken to when we first open up our UNR engine project you can just change this to be whatever you want so once you've set up the game default map you can go over here where say platforms and then you just want to go over to Windows and go package project it will ask you where you want to package your project and then I'm just going to set my desktop and then start to export and package your project there also it may not let you package your project if you don't have visual Studios with like um for game development so if you don't install visual Studios with the game development and then you should be able to package your project okay so my package has finished exporting here it is it's in this folder called windows and if I just open it up I'm taken to my um main menu level pong and I have my pong game hello so the next thing I'm going to do is actually polish up the wind screen if we just head over to the um score widget blueprint go over to the pallette and look for a blur and we want this one background blur to drag it somewhere into the canvas panel and for the anchor select this one in the bottom right and for the offset values just put zero in each value now if I increase this blur strength we can see um the screen will get blurry so I want this to happen when one player wins although you may notice this blur is kind of covering everything with um UI elements inside of unor engine we can control their Z order so right now everything is on the Zero Z order if I just select this background blur it Z order is zero and I want my background blur to be behind every other single um UI element so for the Z order if I make this minus one when I increase the blur strength it's only going to blur everything behind it and this is exactly what I want so now that we've done this if we just check this is variable then head over to the graph when either player wins we can just drag in the background blur get it and just set the blur strength and let's just set it to be 35 and I'll just connect both things into here and for testing purposes I am just going to make the score one again okay it looks like I already did that so if I just go compile and go play if I let one person win we can see player two wins and then it's a lot clearer basically so that's all for this tutorial I hope you've enjoyed and if you want to learn how to create even more full games inside of unro engine check out my website it has a bunch of different courses there that
Info
Channel: Unreal University
Views: 7,259
Rating: undefined out of 5
Keywords: unreal engine 5, unreal engine 5 blueprints, unreal engine blueprint for beginners, how to make pong, how to make pong in unreal engine 5, pong
Id: Vi4tBmv1Mhg
Channel Id: undefined
Length: 55min 40sec (3340 seconds)
Published: Tue Oct 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.