How to make a 2D Game in Unreal Engine 5 - [2024] Beginner Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'll show you how to create a simple 2D game in unre engine 5 from scratch we'll go over importing Sprite sheets and TI sets creating a small stage with ti Maps setting up a character animation switching between idle running and jumping and also the best settings and best practices when making 2D games in Unreal Engine we'll also make many improvements to the movement settings to make the character fun to control I already made a video on this topic about a year and a half ago that got over 600,000 views however a couple of things have changed with unreal and I also made many improvements to the workflow so this will be the definitive unreal 2D video for beginners for 2024 and onward for this tutorial I'll use Unreal Engine 5.3 which is the current version but if you watch this video at a later time you should also be able to use any version newer than 5.3 as well in the project browser click on games and here we have a bunch of different templates sadly there is no 2D template with R engine 5 and the ones you see here are custom templates I made by myself if you're interested in these there's a link in the description where you can get the basic template for free and the two Advanced templates as a patron but for this tutorial I want to show you how to make a 2d game from scratch so let's use the blank template and leave all of the settings on the right as they are by default we want this to be a blueprint project for desktop with the maximum quality preset and no rate tracing and also no starter content then give the project a name and click on create once it's done loading you can see this huge open world map which we're not going to use we want to First create a small 2D stage which our character can stand on click on file new level and select the empty level and click on create we don't want to have any lighting or Skys sphere so this is perfect for making Tod stages to make sure the stage doesn't disappear we'll have to save it click on file save level as in the content folder create a new folder called [Music] Maps change the name of the map to mapor 2D and Save we now want to set this as the default map go to edit project settings and on the left side click on maps and modes for the editor startup map we now want to select this mapor 2D and also for the game default map we want to select mapor 2D this just makes sure that this is the first map which is loaded when we open up Unreal Engine or make a build of the game one more important setting I want to change right now before we import assets is the pi pix per unit setting by default this is 1.0 which means that one pixel for a Sprite is one Unreal Engine unit which is 1 cm in most cases this is much too small though and since our character is 48 pixels tall it would only be 48 cm tall in the game which is way too small for a human this would cause some issues with settings such as the step height and would allow us to teleport up and down Ledges which is something we definitely don't want I believe making the character about three times as tall should suffice and make it about 145 CM which is in a reasonable range and if we type in 0.33 here that will achieve the effect of scaling up our pixel art by three now for all of the assets we'll import and create after this the new pixels per unit setting will be applied the asset pack we're going to use for this video is Legacy Fantasy by anoc colisa which is completely free and distributed under a cc0 license since the asset pack is huge and has many things we're not going to use I prepared everything for easy usage with Unreal Engine and made a repack off the files please download this from the link in description follow along this link will lead you to a patreon post where the files are hosted but everybody can download these even if they're not a member so don't worry just click on it to download the zip file after that you'll have to rightclick the archive and unzip the files here we have the character folder which has the Sprite sheet and the environment folder which has a few tile sets back in unre engine let's prepare a folder for this open up the content draw and right click create a new folder called paper assets we can now just select both the character and environment folder and drag them into our under engine window this should work out for most of you but a few people might have some trouble with this and are unable to drop the files into unal engine in that case you can try using the import button on the top left of the content draw which usually works around that issue now that we have all of our textures and Aral engine let's have a look at the environmental assets if you double click the tore tiles main texture and zoom in you can tell that something is off and it looks very blurry this is because the default settings for textures introduce texture filtering and other settings that don't work well with pixel art to work around that though we only have to rightclick the texture go to Sprite actions and apply paper 2D texture settings this will update the settings to be ideal for pixel art and you can see that when we zoom in select all of the other environmental textures as well by holding shift and clicking all of them and apply the paper 2D texture settings to them as well to use these textures with a tile map we first need to convert them to tile sets let's start with the one on the right which is tore tiles Main and right click it go to Sprite actions and create tile set double click the newly created tile set to open it up here on the tile set editor there are only a couple of things we have to do before we can use these tiles in the game the first thing we need to figure out is the tile size we can see here on the right side that it's set to 32x 32 by default however if we click around on the left side you can see that the size of the square doesn't really match the tiles themselves sometimes the asset Creator will mention the tile size but other times you'll just have to use some trial and error to figure it out by yourself for this asset I know that the correct size is 16 by 16 so we can just type that in now that we have the correct tile size the only thing left to do here is assigning the Collision to the tiles that needed let's start from the top left in the case of this asset we actually don't want to assign Collision to the topmost grass layer because we want the character to nicely stand on top of the grass and not float above it so let's assign Collision starting from the second row we can simply click on ADD box to add a box Collision here on the right side we could also make some adjustments but the default is fine here let's click on the next TI and also add a box here the problem we have now is that it's quite hard for us to tell what we've already assigned Collision to and what we still have left to do we can click on colliding tiles on the top left to show what already has collision and now let's just continue adding box collisions to this one platform after we're done with that we can have a look at all of the other things in the tile set some of these are just background elements that don't need Collision so we can just ignore them other things like this platform would also need Collision but we're not going to use it for this tutorial so we're just going to ignore it we're only going to use this grass platform we already created and I also want to use the bridge so for the bridge let's also quickly add some box collisions for the bottom row here and that's it for TI set Collision the other three textures are only for decoration and don't need Collision however we also have to convert them to a tile set in order to use them for a tile map select all three of them by holding shift right click one of them go to Sprite actions and create tile set for these we don't have to do anything else now let's create a tile map which allows us to use these tille sets we created as a brush to draw a stage look for the Tor tiles mainor tile set right click it and click on create tile map I'll just call it tmore stage double click to open it up one thing I have to tell you about this time up editor is that it's actually quite prone to crashing and the Crash mostly happens if you try to close the toap window so if possible just try to always keep this window open and make sure to save frequently with that out of the way let's start making a very simple stage which our character can stand on here in the middle you can see our tile map area in which we can draw however right now it's very small on the right side I want to set the map width to 50 and also set the map High to 50 to give us some room to work with now on the left side we can just select the entire platform which we applied Collision to to use as a brush and then I want to place it somewhere near the bottom of the tile map but not all the way at the bottom then I just want to place the bridge here and place another platform next to it now I overwrote a small part of the bridge so I'm just going to get the brush again and draw over this again and now we have two platforms and a bridge with working Collision which our character will be able to use I don't like having no background though so I want to implement another layer on the top right you can see a list of the tile layers and we're currently on layer one right click this and rename it to gameplay to make it very easy to understand what this is used for click on the plus icon to add a new layer right click and rename it to background now on the left side we can click on this array looking icon to select our active tile set select the tore skycore tile set first let's just select one of these neutral blue tiles and I want to fill up the entire background with these so instead of the paintbrush I want to select the fill tool and while we're on the background layer just left click our platforms have now disappeared and we need to click on the down arrow to rearrange the layer order and now we have a small stage with a background don't close the time map window because because like I said before there's a risk of crashing unreal but go back to the map and now from the content drawer we can just drag out this tmore stage tile map just to keep things organized I want to reset the location to the default so we can just click this reset Arrow to set everything to 0 one cool thing we can do to visualize the Collision is to click on show and collision now you should be able to see these Collision boxes where we set them up and this can be very helpful for debugging one more thing about the tile maps and tile sets it might not be apparent right now and might also not happen for everybody but in some cases we'll get some really nasty gaps and tile tearing that we need to take care of there is a very easy solution and I advise you to do it either way even if you don't have any issues right now in the content draw for all of our tile sets we want to condition the tile sheet texture this will add some padding which prevents the tile tearing issue let's do it for the tore tiles mainor TI set first just keep the name and press enter ENT and you might see some visual artifacts in the map for a second and that just shows you that the changes have been applied now also do this for the other three tile sets one by one and for now this is all the work we have to do when it comes to the stage and let's now get to the most exciting part which is the character in the content draw go to paper assets and character at this point this is still just a texture of a Sprite sheet however to use this in the game we need to extract these separate Sprites from it and also create our flipbook animations first we want to apply paper 2D settings again to make sure this pixel art isn't blurry but appears crisp then right click the texture Sprite actions and extract Sprites you can navigate this area on the left by holding right click and dragging around and you can also zoom in with the mouse wheel this modal will assist us in extracting our Sprites and our goal is basically to have a yellow box around every animation frame and also make sure they are all of the same size right now we have the Sprite extract mode of Auto selected however this rarely works out and isn't very reliable change this to grid now all of the frames are in a single yellow box which again is not what we want we need to know the size of each animation frame and sometimes the asset Creator will provide a value for that on the download page however the easiest and most reliable way to get this number is to just calculate it right here in this field let's start with the cell width the full width of the texture is 200 as we can see here and we just have to divide this by the amount of columns in this case 1 2 3 4 so we can just write 200 divided by four right here in the cell with field and press enter and then do the same thing for the cell height here we have a full texture height of 280 and again we have 1 two 3 four rows 280 divided 4 is 70 and now all of these cells line up perfectly there are some other settings here such as number of cells margin and spacing however if the Sprite sheet is set up correctly you won't have to fill around with these now just click on extract and you should be able to see all of these separate Sprites in this case we also have two blank Sprites with nothing on them so we can just rightclick them and click on delete if you double click a Sprite you can have a look at all of the different properties most of the settings you don't have to worry about the default material is important however if you use a Sprite through a flipbook animation like we will for this character the material settings on the flipbook will actually have priority and ignore what is being set here on the Sprite the pivot mode will allow you to set the pivot point on the Sprite to a specific location and can can be useful however in this case we won't need it but the most important setting by far is the pixels per unit in simple terms this will allow you to scale the Sprite in relation to Unreal Engine units since we already changed this in the project settings before creating this Sprite you can see that it is now 0.33 which is the value we want now let's create a flip book for each of our different animations a flip book animation is basically just a collection of Sprites that play one after another to give the illusion of movement we can easily create one by selecting all of the Sprites we want included click on the first Sprite hold shift and select the first four Sprites for the idle animation right click one of them and click on create flip book let's call this FB player Idol now let's do the same thing for the Run animation click the character unor sprite4 hold shift and then click on character unor sprite 111 right click one of them and create flip book call this FB player run the last two Sprites you can see here actually don't belong together character sprite 12 is what we want to show when we jump and Ascend and character sprite 13 is the frame we want to show when we are falling even though these are just single Sprites we still want to create flip books for them for ease of use click the character sprite 12 alone right click and create flipbook call it fpor player _ jump rise then click the character sprite 13 right click and create flipbook call it fpor playerall and these are the four different animations we're going to implement in this video now let's double click the idle flipbook to check out the flipbook editor in here you can see the flipbook playing and you can also pause the playback and scrub through the timeline slowly the most important setting here is the frames per second setting if you set this to a low value the animation will play out very slowly and with a high value will play out really fast in this case I think a frames per second value of five feels about right now let's do the same thing for the Run animation here a value of five definitely looks too slow and I think nine looks about right for the regular run speed the fall and jump rice are only a single frame so we don't have to worry about the FPS setting now just to clean things up we can right click and create a new folder called Sprites and another new folder called flip books and then just separate these the Sprites have a blue line on them and say Sprite at the bottom just click one hold shift click the others and drag them in here select move here and then just do the same thing for the remaining flip books with the green line we can now close the window for the Sprites but keep the tile map open to prevent editor crashes awesome we now prepared all of the art assets we need for our character so let's start working on the character blueprint in the content folder right click and create a new folder called blueprints open it up right click again and create a new blueprint class out of the common ones the character parent class is the closest thing to what we want however there actually also is a parent class specifically for paper 2D characters under all classes here we can just search for paper and you'll be able to see the paper character mark it and click on select let's call this bpor player and open it up in the viewport you can see that we have very basic things set up since we inherited from the paper character we have a capsule component that will take care of our collision with the world this thing which is called a Sprite is actually a flipbook component which we'll be using to playback our flipbook animations and the character movement component makes it very easy for us to set up a character that can move around jump and all of those kind of things just by changing a couple of settings let's take care of the Sprite first click the Sprite component on the right side for the source flip book we now want to select the FB player Idol now since we already set up our pixel per unit settings in the beginning the Sprite is already a pretty good size and almost fits the capsule perfectly but we can now go to the capsule component and make slight adjustments for the half height I think a value of 75 is is perfect for the Caps the radius I believe that 25 feels about right we don't have to worry about the sword since it's okay for that to stick out and be ignored aligning the feet perfectly with the capsule is a bit tricky but we can slightly move the Sprite downward on the z-axis by minus 2 now let's place the character in the world and get a feel for what it looks like drag an instance of the BP player out into the map and just make sure that it's on the same Lane as our stage the easiest way to do this is to just make sure it's set to zero on the Y AIS otherwise it might not be on the same Lane as the collision and just fall down now if we start the game we can see that gravity takes effect and the character nicely stands on the platform however we can see a little bit of flickering because the gameplay layer on the tile map and the character are in the exact same position on the y a simple fix is to just select a DTM stage and on the Y move it slightly backward I think setting it to minus 0.1 is fine and now when we start we can see that the character nicely appears in front of the platform we still can't control the character however I first want to take care of some 2D settings in some cases when working with ti Maps if you press on start everything might start becoming very bright little by little and also the colors of the scene might look a bit strange Unreal Engine is of course set up to make 3D games look good by default and those settings are not fighting against us and we have to make some adjustments I've struggled quite a while finding all of the right settings but there is actually a great blog post by U 52d da which sums it all up nicely and I'll use that as a reference go to edit and project settings First Look for motion blur and turn this off this can look very cool in 3D games however blurriness doesn't go well with pixel art then look for anti-aliasing and for the anti-aliasing method select none anti-aliasing is a technique that removes jagged lines however again for pixel art this is something we don't want next look for auto exposure and turn it off also set the auto exposure bias to zero next we want to look for Global illumination and set the dynamic Global illumination method from Lumen to none Lumen is the new Global illumination system introduced in IR Engine 5 however since our 2D stage won't have any lights there is no benefit to using this then look for reflection method and also set this from Lumen To None next look for shadow map method and set this from virtual Shadow maps to Shadow Maps this is the old method that should be a bit more performant in our case lastly look for ambient occlusion and turn both of the these off ambient occlusion is a shadowing technique for 3D objects but again we don't have any lights and 3D objects so there's no benefit to using this all of the other settings we cannot set in the project settings but have to create a postprocessing volume for our level to create one we can click on the ad icon here volumes and click on postprocess volume just so we don't lose track of it we want to put it to the 000000 location which we can do by just clicking on this reset Arrow now we always know where to find it you can have volumes like these which only affect a certain area in a stage however you want it to affect the entire stage so the position doesn't matter while it's selected we can just search for infinite and set infinite extent Unbound to true this means it will affect our entire stage regardless of size and position now we can take care of the remaining settings look for Ev 100 both the min ev100 and Max ev100 affect the auto exposure and can make the brightness of our Sprites inaccurate we just want to set both of these to 0.0 next look up vignette intensity this creates a darkened Rim around the edge of the screen which is something we generally don't want for 2D games so set this to 0.0 as well next look for expand gamut this will affect the colors of your Sprites and might make them look unnatural set this to 0.0 as well lastly let's look for tone curve this tone curve amount will again affect the colors of your Sprites in some cases this can look quite good and give the image a bit more contrast however if you want to keep the original Sprite color you want to set this to 0.0 as well and now our 2D game looks a lot more pure and very close to how the Sprites have originally been drawn so these are some settings you always want to apply to your 2D games if you end up adding more stages to your game you just want to copy paste this postprocess volume and place one in each of your stages to app apply the same settings next up we want to control the character and set up the camera right now if we click on Play We just have this free flying camera because Unreal Engine doesn't know which Pawn we want to possess and spawns a new default Pawn for us the best way of setting the pawn is to create a game mode open up the content drawer go to the blueprints folder and right click go to blueprint class and here we have a game mode base which we can use as the parent class call this gmor platformer and double click it to open it up this is a fullon blueprint which we can use in many different ways however for now we only want to look at the right where it says classes and for the default Pawn class select our bpor player to let an know we want to control this character but now if we press play nothing has changed because we also need to let unre know that we want to use this game mode we just created click on edit and project settings then on the left side click on maps and modes for for the default game mode we want to select our gmor platformer now if we start the game you can notice that something is very different we are now falling and still don't really see what is going on what is happening here is that Unreal Engine spawns a new instance of our BP player in our current position however we want to spawn on top of the stage select the player we currently have here and hit the delete key on your keyboard to delete it then click on the plus icon go to basic and look for player start this is an object that lets un engine know where we want to spawn our default Pawn we can drag it into position and then also make sure that the green y- AIS is set to zero to line up with the ground now if we start the game we're at least not falling anymore but we still don't see our character if you click on eject though and move around you can see that the character is indeed being spawned and we are possessing it we just haven't set up our camera yet so it instead puts us in this weird first person view to alleviate that is issue let's open up the bpor player blueprint while the capsule is selected we want to click on ADD and look for spring arm while the spring arm is selected click on ADD again and add a camera now we want to change this to a sideways view select the spring arm go into rotate mode and drag on the blue axis by minus 90° so we now look at the character from the front now when we start the game we can finally get a good look at our character all of this already looks pretty good but we can make a few more adjustments first of all we want to go to the camera and set the projection mode from perspective to orthographic the effect of this might not be instantly apparent but this removes all depth from our scene and creates a more pure 2D look the orthographic camera actually used to be quite buggy and it wasn't recommended however it has seen many updates with unine 5.3 and will hopefully continue to do so now to change the distance of the camera we cannot use the target arm length on the spring arm anymore instead on the camera we can now change the ortho width The Wider this is the further away the camera will appear let's set this to 700 and you can now see that the camera appears further away lastly on the spring arm we want to look for do Collision test and deactivate this if this is active and something is between the camera and the player character it will forcefully zoom in if you're making 3D or 2D 3D hybrid games this might be useful in some cases but for 2D only games this will often just lead to bugs and confusion now that we are possessing the character and have the camera set up we need to set up the input bindings and allow the character to move and jump since un engine 5.1 the new enhanced input Action System has become the default and we'll be using that for this tutorial it might be a bit hard to wrap your head around at first but it has a lot of great buildt and functionality and will save you a lot of time in the end let's open up the content drawer and go into the content folder right click and create a new folder called input open this up right click again and create a new folder called actions the input system basically consists of input actions which are certain actions we want the character to execute such as move jump attack and so on and an input mapping context that binds these actions to a certain button and can also apply modifiers let's first go into the actions folder right click input and create our first input action I'll call this I aore jump when we double click this we can see a bunch of options but the only one we really care about is the value type currently this is set to digital Bool which is correct for an action like jumping this means that the input for this action can either be active or inactive and that is the case for a regular button create another input action called iore move open this up and here we actually want to change the value type the move action can be executed with a left or right button on the keyboard but in many cases we'll also add controller support for the anlock stick later on this means it's not just an on or off value but it could be a value between minus one for left zero for neutral and one for right since we only want to support left and right we want to use the value type of AIS 1D float which gives us a range from minus one to one on a single axis now that we have both of our actions set up we want to go back to the input folder right click go to input and create an input map in context I'll call it imcore platforming double click to open it up in here we now have to register the jump and move actions we created to bind them to a button where it says mappings click on the plus icon and then on the carot to expand the menu click where it says None and select I a jump now again expand the the menu and here we can set up which button we want to use for jumping just click on the keyboard icon and then press the key you want to assign I'll just use the space bar for jumping and this is all we have to do for the jump click on the plus again and add a mapping for IIA [Music] move here things get a little bit more complicated first you want to assign the D key on the keyboard for Right [Music] movement and then we want to create a another binding and then for the other binding we want to set the a key for walking left now both of these buttons do the same thing though and we need to differentiate between them for walking left and right since we selected a 1D axis float here we need to flip around the input for left and the a key so here we can go to modifiers and add the negate modifier by default in AIS one you will point to the right so for D we get the value of one but if we use the negate modifier for the a key we'll get the the value of minus one instead which is what we want but again if we press play now nothing really changed we still need to tell the character to use the input map in context and then also what code to execute when we trigger the Ia jump or IIA move open up the BP player and go to the event graph we need to activate the input maping context on begin play right click and get controller drag off from the return value and cast to player controller connect the line to begin play from the player control drag off and look for subsystem and get the enhanced input local player subsystem here drag off and look for add mapping context and then connect the lines very important on the ad mapping context we need to assign our IMC platforming or this entire enre thing won't work now that this is set up we can just move to the side a bit right click and look for our IA jump we can then expand this and drag off from started and use a print string that says jump just to demonstrate how this works go further down and then just look for IA move and here we can drag off from triggered and print string and just drag in the aess value now go back and start the game and very important we need to click into the viewport with the mouse one time to start controlling the game and now if we press space you can see that it says jump when holding a it says minus one for left and when holding D it says one for right now that this is working we want to put in the actual code to make the character jump and walk and with un engine this is rather simple for the jump just delete the print string drag off from started and look for the jump function then drag off from completed and look for stop jumping and this is the default setup for jumping and all it takes to make the character jump when we press space to make it move we can again just get rid of the print string here next to the I move drag off from triggered and look for add movement input here we connect the axis value to the scale value and we need to set the world direction if we go back to the map and select the player start we can see that the red arrow is the direction we want to go if we drag around the red arrow we can see that the x value is updating and this means we want to move our character on the x axis so for the world direction we put in 1.0 on the X and leave Y and Z at zero now when we start the game and click into the viewboard we can walk left and right and all of this might seem like magic to you but the jump function and the add movement input function are nodes that unre engine has prepared for us these are things that are commonly used in all types of games so there's no need for us to reinvent the wheel of course right now there are still a couple of issues with our character which will solve step by step but this was the General way you go about setting up inputs and adding new actions to a pawn let's now make sure that we transition properly between the idle walk and jump animation since this will make the game feel much more complete open up the bpor player and look for the tick event The Tick event will be fired off on every single frame and is the best way to keep something like an animation State up to date first we just want to switch between the idle and walking State and to determine if we need to switch or not we only need to know if the character is currently moving or stationary to do that we can just right click and get velocity and then look for Vector length we don't really care about the direction in this case and Vector length will simply give us a value of zero if we're not moving or a positive value if we are moving so here we can simply check for greater than zero then put a branch here which basically is an IFL statement if you're familiar with other programming languages then we can drag out a reference to Sprite Which is actually the flipbook component and here we can then call set flipbook and set the new flipbook to fpor player run then connect this node to the true output of the branch you can also double click these lines to create reroute nodes to organize the blueprint a little bit then we can just select all of this contrl C to copy and then control V to paste and connect it to the false case here for the new flipbook we want to select the FB player idle and now we can just go back to the map and press play to check this out we are now correctly switching between the walk and idle animation if we are moving next up we want to put in the jump rise and fall animation as well first you want to clean this up a bit and we can select all of these nodes we use for switching between the run and the idle if you can't select all of them at once you can Al shift or control to get them in multiple goes then right click one of them and collapse to function call this update animation and move it over now double click to open it up this still does exactly the same thing but it's encapsulated nicely and a lot easier to maintain now at the place before we decide between the ID and run we want to open up some space Here We Now look for is moving on ground which is a method available on the character movement component and here we can add another Branch connected and then also connect the true output to what we were doing before because if we are moving on the ground we need to decide between the walking and idle like we have been doing before now for the false case we want another branch and here we want to check if our character is currently going upwards or downwards for this we can just get velocity right click the return value and split struct pin now we need to know if we want to use the X Y or Z again if we go to the map and click on the player start we know that the blue arrow is up or down and if we drag this around we can see that the zv value is the one that changes so back in the blueprint we can then check for the return value Z and see if it's smaller than zero this means that we are falling down or descending so here we can copy paste this Sprite and set flipbook and for the new flipbook select the FB player fall then copy paste this again and in the false case place the FB player jump rise and now you can see that we can properly switch between the jump rise and the falling animation a nice little trick to make the transition a little bit smoother is to not check for smaller than zero but check for something around minus 100 that way we don't switch animations directly at the apex of the jump but after descending a little bit this just makes it feel a bit more natural in my opinion and this is all it takes to set up animation switching for your paper 2D flip books for simple things like with did now this method works just fine however once you make more complicated games with a lot more animations this can be a bit hard to manage for that reason somebody made a free plugin called paper ZD which adds support for animation graphs that make handling animation States much simpler this is definitely something that will make your life a lot easier when making 2D games with Unreal Engine I actually made a full 12-hour course about 2D game Creation with Unreal Engine in which I teach you how to create four awesome games we start out slowly by creating a simple quick draw mini game then move on to creating a classic arcade Masher game and the last two projects will make use of the free paper ZD plugin and we'll go into detail on how you can set it up and get the most out of it when making more complex games we'll use this to create a platformer game with enemy Ai and gimmicks and lastly to also create an action platformer in a 2d 3D hybrid style that includes Mele combat and some Metroid Vania elements so if you're interested in mastering Unreal Engine 2D check out the discount Link in the description the next thing we want to do is make our character turn left and right when walking because now we're always just pointing to the right this is actually quite easy to do back in the bpor player we want to go back to the event graph and look for our IA move event after the add movement input we want to right click and get controller then drag off here and set control rotation we can drag off from new rotation and look for select use the utilities select here this acts very similarly to a branch but in situations like this it can be a bit easier to use this will now basically just let us pick between two options for setting the character's rotation and how do we decide this well the action value will be something negative for left and something positive for right so we can just drag off and check for greater than zero and plug this into the index let's start with the true case drag off here and look for make Rotator and select the one all the way at the bottom if this is true we want to point right so for this we can just leave everything at zero for the false case again make Rotator when moving left we want to turn the character by 180° on the z-axis so here we can just put in 180 now if we start the game and walk right everything is fine but if we walk left you can suddenly not see the character anymore this is actually a sign that the turning is working correctly you can shift and F1 to get the mouse pointer back and then click on eject to see what's going on we can see that the character is now correctly pointing to the left however the camera also turned with the character and is now on the opposite side of the tile map let's stop the game and fix this really quickly on the BP player go to the spring arm and on the right side click on rotation we want to set this to World which will then show up as absolute rotation and now if we try this out you can see that we are properly turning left and right and the camera is ignoring the rotation of our character but our character still feels very floaty and not fun to control this is because the default settings on the character movement component are not that great open up the BP uncore player and select the character movement component here just look for gravity and set it to something like 3.0 now if we play the game you can see that the character Falls much faster but we also need to change the jump power to accommodate for that back on the character movement component look for jump velocity and set this to 800 we can then also set air control to something like 0.7 to make the movement in the air more responsive and all of these are just some values I found through trial and error that I believe make the character more fun to control one more problem we have is that if we try to walk off the ledge instead of falling instantly we just awkwardly walk downward slowly this happens because of the capsule component in the BP player and capsules are really nice if you have stairs and slopes but for things like these they can lead to problems luckily though there's a simple setting for this on the character movement component just look for floor and activate use flat base for floor checks and now we fall instantly like it is the case with most 2D games one last setting we want to adjust on the character movement component is the movement constraint even if we make a 2d game and only have an input setup for left and right it could still happen through physics or forces that we are being pushed into the foreground or background to prevent this we can go to the character movement component in the BP player and look for constraint activate constraint to plane and in the plane constrain normal we need to set the direction in which we want to constrain the movement again if we look at the player start we can see that the green axis is the one which we want to prevent movement in and this is the Y AIS so on the y- axis we just set the plane constraint normal to 1. Z to activate it and now we can be absolutely sure that the character will never leave the original Lane and this is all we have to do to set up the base for a 2d game in Unreal Engine this might seem like a lot and yeah it is a lot to remember but once you've done this a couple of times it feels like second nature however I actually made a free template that is open source that already has all of this set up you can easily add this to Unreal Engine and create all of your new 2D projects from it so you don't have to go through all of these steps every single time you want to make a 2d game but it's very important that you followed along with this tutorial and did everything at least once so you can understand how all of these different things work and expand upon them and as a patron you can also get two more advanced templates that use paper ZD animation graphs and there is one version for a 2d 3D hybrid side scroller and another one for a 2d 3D hybrid top down game and now to wrap things up we can just go into the tmore stage and expand up on our map to make things look a bit nicer making tile Maps isn't something I'm necessarily great at and you can just go wild on your end and use all of the tiles we have available here to make a stage you like I'll add a couple of more layers to add clouds props decorations and other things to dress up the stage a little bit and this is the small stage I ended up with after playing around with it for a little bit and I hope you enjoyed this introduction to making 2D games with Unreal Engine as always thanks to my amazing [Music] patrons
Info
Channel: Cobra Code
Views: 229,978
Rating: undefined out of 5
Keywords: unreal engine 5, paper 2d, unreal engine 2d, unreal engine 5 tutorial, unreal engine 5 beginner tutorial, paper 2d tutorial, unreal engine 5 side scroller, unreal engine paper 2d, Unreal engine 5 2d game, unreal engine 2d game, how to make a 2d game in Unreal Engine 5
Id: QVxK2dPJr4g
Channel Id: undefined
Length: 45min 51sec (2751 seconds)
Published: Wed Jan 17 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.