Creating Your First Game in Unreal Engine 4: Part 1 - Setting up The Camera

When it comes to learning game design the best route to take is to jump in and start creating a game. No, I don't mean the next best first person shooter. As someone just starting out you need to take it slow. An artist doesn't start creating photorealistic portraits day one of their learning, no, they probably experiment with lots of stick figures and drawings there probably never going to show anybody. Your goal should be to make a game, any game, with a set objective and a way to accomplish that objective. It doesn't need to be complex, in fact, in should be as simple as you can make it. As long as you can finish it. In this brand new series, I'm going to walk you through the process of creating a very simple game in Unreal Engine 4 utilizing Blueprint for the entirety of the coding. If you've never used UE4 before I recommend reading Mastering the UE4 UI, and checking out our in-depth introductory tutorials at the Digital-Tutors library. The goal of this series is to give you a strong foundation in Unreal Engine 4, comfortable with Blueprint and the steps you should take when tackling your own game.

Deciding on a Game

Okay, so before we ever jump into Unreal Engine 4 we need to have an idea of what it is we are going to be making. Maybe you have an idea of a top down maze runner where you have to battle aliens along the way with a massive laser gun, or a Mario-type side scroller where you must get from point A to point B while staying alive and fighting off a horde of Orcs. You can jump, flip, climb, kick and shoot the Orcs with a crossbow. Sounds pretty cool, right? The only problem with these ideas is that they are too complex! Way too complex, especially for our first game. We don't need to think about if this game can make it onto the App store, this is specifically for learning purposes. Now that we've gotten out any fantastical ideas of various complex games we could be creating, it's time to get a little more realistic with it, and decide on a game we can take from start to finish that will teach us a lot about Unreal Engine 4. So the game I'm going to show you how to create is about as simple as it can get. The goal of the game is to get the ball into the basket. I know, it's not very exciting, but we can learn a lot from a game like this. The camera is going to be fixed in the side view, and the majority of the game is going to be driven by gravity. The ball is going to start at a certain position in the level, and the player will have several platforms that he or she can move in each level. The player must move each platform in the right spot in order to bounce the ball into the basket. As each level progresses it gets more difficult, more platforms will be introduced like boosting platforms that will launch the ball further and higher. I know, it's simple, and a puzzle game is probably not the most exciting, but it's an excellent place to start for our first game, and it's a game we can finish.

Make a Task List

Before we start making our game, it's a good idea to first create a task list. A task list is basically what it sounds like, a list of the tasks that we need to accomplish in order to create a finished game. It's good to break up a game into bite-sized chunks like this. Simply saying, "Okay, I'm going to create the game now" isn't realistic because that is a big undertaking. Where do you start? That's where the task list comes in! Based on the things I mentioned above I have a good idea for everything that needs to be created. The camera is going to be locked in the side view, so I know I need to setup a new Level Blueprint that activates the new camera when the game is started. I know I'm going to need several geometry pieces, which can be created in a 3D application and imported in, or we can use BSP Brushes. For now, however, BSP brushes will work just fine, the geometry is going to be mostly simple geometric shapes like cubes. Eventually we may want to swap the BSP brushes for regular 3D meshes, but in reality we aren't going to run into performance issues by using BSP geometry, because the game is extremely simple. I also know I need to create some type of basket for the ball to drop into. I imagine the basket being very simple, just a ring of bright light, something very Tron like. I know a new material will need to be created for this. There will also need to be some UI elements created, a simple Start or Play button when the player has positioned their platforms in the right spot, and a restart button. These are just some of the things that will be included in the task list.

Setting up the Camera

Okay, so now we know what game we are going to be creating. It's simple, but there is still a lot to be done! As I mentioned the camera is going to be locked in the side view, and the player shouldn't be able to move the camera around at all. Going off my task list, setting up the camera was the first thing I wanted to accomplish first, and at least have it in the basic area that I wanted. UE 4_ New Project In order to begin creating our game we need to start a new project, so in the Unreal Project Browser I selected New Project, and choose the Blank template and kept the Include start content box checked. UE 4_ Default Scene Now you should see the default Unreal Engine scene with the floor and table and chairs. We will eventually delete theses meshes, but for right now we can just keep them in our game. If we were to run the game by pressing the "Play" button in the toolbar the camera would be based on the player start position and we can move around the game using the WASD keys. This default game camera is not going to work for the game we're creating. For our game, the camera needs to be fixed in the side view, and the player can't move it around. Creating a new camera is a little more involved than just placing a new camera in the scene, because we need to add a Blueprint to tell the game that we want it to play through the new camera view. UE 4_ New Camera Let's first add a new camera into the scene, so go into your Modes panel, under the Basic section choose "Camera", and drag it directly into the scene. Now just select the camera and rotate it 180 degrees until its looking directly at the table and chairs. You should see a preview of the selected camera angle in the right side of the viewport. I've also changed the name of the new camera to "Game_Cam". UE 4_ Open Blueprint With the camera still selected in the scene go to Blueprints in the toolbar and choose Open Level Blueprint. UE 4_ Add Reference This opens up our Level Blueprint editor and is where we can tell the engine to display the new camera when the game is played. So the first thing we need to do is setup a call function. Right click anywhere in the graph view of the Blueprint Editor and you should see a new box appear, this lets you add in various functions to the Blueprint. We want to choose "Add Reference to Game_Cam". By doing this, the engine now knows which camera we want to affect. UE 4_ Event Begin Right click in the graph view again and type in "Event Begin Play" into the search bar, this will display the exact event we're looking for. This node is only ran once, and basically says, when the game is started, complete this action. UE 4_ View Target Right click again in the graph again, and first uncheck the "Context Sensitive" box in the top right corner and search for "Set View Target." UE 4_ Player Controller Finally, we need to add in one more function, so right click again and search for "Player Controller" and choose "Get Player Controller" UE 4_ Final Nodes Now just connect each node like you see in the image above. With this Blueprint we're basically telling the Engine that when the game starts (Event Begin Play) set the view (Set View Target with Blend) to the Game_Cam for the player (Get Player Controller). CompileNow select the "Compile" button in the Blueprint toolbar and if you get a check mark you're all good to go! UE 4_Game Cam When you play the game, the camera should now switch to the new Game_Cam we created and assigned in the Level Blueprint. Pretty cool, right? UE 4_ Orthographic One last thing we can do is change the projection type of the camera, while we have the camera rotated straight at the table and chairs we are still viewing it in perspective mode, to change this select the camera and in the details panel check the projection type from Perspective to Orthographic. You can also uncheck the Contain Aspect Ratio box. UE 4_ Final Game Cam When we run the game now we should now have a camera that is in a perfect orthographic position that can't be moved or rotated by the player, which is what we want. In this article, we learned about the importance of creating a game that is simple enough that it can be accomplished in a reasonable amount of time. We also learned how to setup the basic camera for our action packed game using Blueprint! Okay, so the game is not going to be very action packed, but you'll definitely have a strong understanding of Blueprint and the basics of Unreal Engine 4 by the end of this series. Be sure to check back to blog for Part 2 where we dive into level creation.