Book Image

Game Development with Blender and Godot

By : Kumsal Obuz
Book Image

Game Development with Blender and Godot

By: Kumsal Obuz

Overview of this book

Game Development with Blender and Godot is a comprehensive introduction for those new to building 3D models and games, allowing you to leverage the abilities of these two technologies to create dynamic, interactive, and engaging games. This book will start by focusing on what low-poly modeling is, before showing you how to use Blender to create, rig, and animate your models. You will also polish these assets until they’re game-ready, making it easy for you to import them into Godot and use them effectively and efficiently. Next, you will use the game engine to design scenes, work with light and shadows, and transform your 3D models into interactive, controllable assets. By the end of this book, you will have a seamless workflow between Blender and Godot which is specifically geared toward game development. Alongside, you’ll also be building a point-and-click adventure game following the instructions and guidance in the book. Finishing this game will help you take these newly acquired skills and create your own 3D games from conception to completion.
Table of Contents (20 chapters)
Part 1: 3D Assets with Blender
Part 2: Asset Management
Part 3: Clara’s Fortune – An Adventure Game

Creating a low-poly barrel

Every discipline comes with a few conventions for beginners. If you are learning a new programming language, writing “Hello World” to the screen is a classic example. Learning how to use 3D modeling software is no different. For example, a barrel, a potion bottle, or a donut can be started with basic shapes you are familiar with, such as a cylinder, a cone, or a torus, respectively.

In this section, you’ll learn how to design a barrel but, first, here are a few useful shortcuts that will help you navigate around and accomplish the tasks we’ll cover in this section:

  • Rotate: Middle mouse button + drag mouse
  • Zoom: Scroll mouse wheel forward/backward
  • Move: Shift + Drag Mouse

Blender is rich with so many shortcuts and it’s possible to change them to your liking once you gain more experience. Speaking of shortcuts, this book only lists Windows shortcuts. However, when you see the Ctrl key mentioned, it’s the Command key in macOS.

When you launch Blender for the first time, you’ll be presented with some options. One important option is to decide which mouse button to use to select objects. Historically, the right mouse button was the default, but you may find this uncommon. If you dismissed that initial screen, and you are not happy with the mouse button assignment for the select operation, you can still change it by going to the Edit menu and selecting Blender Preferences. In the Keymap section, expand the Preferences section, as shown in the following screenshot; you’ll be able to change a bunch of settings, including Select with Mouse Button:

Figure 1.4 – The Preferences window of Blender

Figure 1.4 – The Preferences window of Blender

Speaking of the select button, whichever side you choose, the other side will be reserved for moving the 3D cursor to a new position. A 3D cursor is a visual marker you place in the world. When you add new elements to your scene at a particular location, or things need to align to a certain point, the 3D cursor will be that point. We’ll most likely keep the 3D cursor where it is for most exercises, but keep in mind that if the left click is for selection, then the right click is for the 3D cursor, and vice versa.

Official manual

Since this book is about game development, we’ll focus on a small and relevant portion of Blender. However, sometimes, looking at the official manual might be a good idea, especially for shortcuts. The Blender website has a decent user manual:

Modeling is a multi-step process. It involves starting with the basics and adding more details as you go. The following is what we’ll do to design a barrel:

  • Start with a primitive
  • Edit the model
  • Shape the body
  • Separate the lid
  • Finish the body
  • Place metal rings
  • Finalize the lid

The list is merely an example workflow that highlights useful parts of Blender. When you gain more experience and find a different order to accomplish what you have in mind, you can work in whatever way works for you. However, you are likely to start with primitives.

Starting with a primitive

A new scene in Blender comes with a cube, a camera, and a light source. Since we are going to create a barrel that is more like a cylinder, we should get rid of that cube:

  1. Select the cube and press X on your keyboard to delete it.
  2. Trigger the Add menu to the left of the Object menu.
  3. Select Cylinder under the Mesh group.

The shortcut for adding new objects is Shift + A, which will bring up the same list of options. If you feel like deleting the other default objects, feel free to do so since you can always add them later using the Add menu. The following screenshot shows where you can find it:

Figure 1.5 – You can add many types of primitives to your scene

Figure 1.5 – You can add many types of primitives to your scene

Once you add the cylinder to your scene, you’ll see that the cylinder comes with a lot of side faces; 32 to be exact. For a low-poly barrel, that’s a lot of faces that could be cut down by half and you would still have a decent-looking barrel.

When you add a new object, a panel will appear at the bottom left of the screen. The title of this panel will reflect what you are currently trying to accomplish. In this case, it should display Add Cylinder. If it looks closed, click the title and it’ll expand to show the properties you can alter for your cylinder.

The default options are all fine except for the number of vertices. However, this is also a good chance to play with the values and see the changes reflect instantly. While you are doing all this, that panel may disappear if you click away from your cylinder. To bring it back, click Adjust Last Operation under the Edit menu. When you feel like you’ve got the hang of editing a new object’s properties, you can set the relevant values, as shown in the following screenshot:

Figure 1.6 – 16 faces will be enough for creating our barrel

Figure 1.6 – 16 faces will be enough for creating our barrel

Adding a primitive such as a cylinder has introduced a new object to your scene. You’ve changed its basic properties, such as the number of vertices. That number defines how many points are used to make up the top and bottom circles, as shown in the preceding screenshot. This was all done at the object level; hence, you’ve been working in Object Mode. Now, it’s time to dive deeper and edit the finer details of this cylinder.

Editing the model

It may seem like every time you change the value of something, you are editing the model. However, from Blender’s perspective, not all edits are the same. When you start with primitives, there are higher-level operations you can perform such as changing the number of vertices that define the general shape of the primitive. This is what you have seen and done so far – you’ve been editing objects.

When you want to have more control over the vertices, faces, and edges that make up the object, you should switch to another mode that allows you to work with these properties so that you can have much more refined control over the shape of the model.

Mac shortcuts

You can always use menus, buttons, and other interface elements to do your work, but you’ll eventually depend on shortcuts. If the shortcuts that have been mentioned so far don’t work for you, then you may want to check out Blender’s manual to find the right combination for your platform:

Select the barrel and press Tab. This will turn on Edit Mode. If you keep pressing the Tab key, you'll go back and forth between Object Mode and Edit Mode. You’ll also see that Blender’s UI is either hiding some of the buttons and menus or revealing some new ones, depending on which mode is active. This means some options are only available in a certain mode. If you are wondering where that thing you just saw disappeared, make sure you are in the right mode.

Then, in Edit Mode, press Ctrl + R to trigger Loop Cut and Slide. This is a context-sensitive operation, so if you see nothing happening, it’s because the mouse is not over a face for this tool to operate. Hover your mouse over different parts of the cylinder. You’ll see a yellow line going all the way around; the direction of the line depends on where your cursor is on that face. While still over one of the side faces, trigger your mouse wheel up twice to increase the number of cuts to 3. This is a preview of the loop cuts, but they are not part of the cylinder yet.

A loop cut will require two mouse clicks, regardless of how many loops you would like to have. With the first click, you are telling Blender that you want to introduce some cuts; in this case, 3. The second click will finalize the position of these cuts, but you can change it by moving your mouse up and down along the side of the barrel. So, in between the first and the second click, you have some freedom to position the cuts. The following screenshot shows what we are after:

Figure 1.7 – Adding more edges with precise values

Figure 1.7 – Adding more edges with precise values

If you accidentally moved your cursor in between two clicks, which would have moved the baseline of the cuts, do not worry. Once the edges have been added, the operation’s details will be displayed so that you can fine-tune where the cuts appear in your model. The important part is to set Factor to 0 so that you have the perfect cut in the middle. If you made a last moment change before you made the cuts, you can also adjust the number of cuts.

The main reason why you switched to Edit Mode is to have more control over the shape of your objects. While still in Edit Mode, you’ll now learn how to use those loop cuts to give your object the shape of a barrel.

Shaping the body

A barrel is such a generic concept. However, we have not discussed what kind of barrel we will be working on. Technically, we are not too far off from an oil barrel since they usually look cylindrical and have two rounded-off ridges. Then, there are plastic barrels that you see in gardens for collecting rain. These tend to have a plain side with the top and bottom slightly tapered in or with the middle section slightly bulging out, depending on which way you look at it.

We’ll go for a more classic one: a wooden barrel. Since we have the basic shape, we can now start adding more details to our barrel. Two things come to mind easily. Most barrels have a few metal rings – in the middle, near the bottom, and at the top – for enduring the stress of what they are holding. Also, the lid is rarely flush with the side but more likely inset, so maybe we should treat that top part separately. Let’s start tackling all these one at a time.

Are your 3D objects looking flat?

It’d be nice to have some life in all that gray! If the default look for 3D objects feels too flat and you’d rather see the edges emphasized like you see them in pictures, here is a trick. There is a button with a down-looking icon at the top-right corner of the 3D Viewport. If you click that button and expand the Viewport Shading panel, you can switch Lighting to MatCap, and turn on both the Shadow and Cavity options in the panel. Selecting Both for the Cavity type may also be a good option. Investigate different values as you see fit so that you have an easier time working with your models.

Our barrel needs a belly. We need to make those loops we have just introduced wider to create a classic shape for the barrel. With those three edges still selected, hit S, type 1.1, and press Enter to scale it up by 10%. As usual, the last operation’s fine-tuning settings will be shown if you would like to adjust your values after finishing the action. Now, we only need to make the middle ring slightly larger.

Although we have been in Edit Mode so far, we have not investigated what you can edit. In the top-left corner of 3D Viewport next to the Edit Mode dropdown, you’ll see Vertex, Edge, and Face icons from left to right. These buttons have 1, 2, and 3 as shortcuts, respectively.

Switch to Edge edit mode by pressing the middle icon or 2. To create the belly for the barrel, you need to select and scale up all the edges that make up the middle ring, but you probably don’t want to do that for each edge one by one. Thus, we need to look at how to select an edge loop.

There are two ways to select an edge loop. The first method uses a keyboard shortcut:

  1. Hold the Alt key.
  2. Click one of the edges.

This should select all the edges that are connected to the one you’ve just clicked, as shown in the following screenshot:

Figure 1.8 – Selecting all the edges that make a loop is easy

Figure 1.8 – Selecting all the edges that make a loop is easy

The second way is as follows:

  1. Select one edge.
  2. Go to the Select menu.
  3. Expand Select Loops and choose Edge Loops.

Whichever way you do this, after you select the middle edge loop, you must do the following:

  1. Scale it by pressing S.
  2. Type 1.05.
  3. Hit Enter.

This should result in a classic barrel shape.

However, the top face still belongs to the cylinder. Although conceptually, a lid might be considered an essential part of a barrel, from an editing perspective, it must be treated as a separate object. Let’s learn how to separate parts to edit them individually.

Separating the lid

To create the lid, first, make sure you are still in Edit Mode. Switch to face select mode by clicking the third icon next to the Edit Mode dropdown or by pressing 3. Then, do the following:

  1. Select the top face.
  2. Press P.
  3. Choose Selection.

This will separate the top face and make it a separate object.

Alternatively, you can expand the Separate group under the Mesh menu. The following screenshot shows where you can find this option if you are doing the separation with the menus:

Figure 1.9 – Separating things is sometimes necessary and, in fact, helpful

Figure 1.9 – Separating things is sometimes necessary and, in fact, helpful


At this point, you must have noticed that Blender uses a lot of shortcuts. It might be difficult to learn and remember all these at the beginning. If you have a rough idea about what you’d like to do with the meshes, vertices, edges, and such, you should check out the appropriate menus near the top to see what operations are available. Pressing a shortcut key will show you just the relevant part of those menus, but investigating those menus and looking at the shortcut might be a good exercise.

For example, the P key is used to separate things, but there are three types of separation, so you’ll still have to make a final decision on the type. However, using the shortcut still takes a shorter time than expanding the menus.

Now might be a good time to introduce you to Outliner in the top-right corner. The following screenshot shows all the objects that exist in your scene right now:

Figure 1.10 – The lid and the body should be two separate objects

Figure 1.10 – The lid and the body should be two separate objects

You can ignore the Camera and Light objects if you kept them in your scene since we’ll discover what those two do later in this book. Over time, when you create more objects, you’ll want to label your objects so that you can easily find them in Outliner.

Let’s try it now. Double-click the label for Cylinder in Outliner and type Body. Do the same thing for Cylinder.001 and mark it as Lid. You’ll also notice that clicking labels in Outliner will select the objects in 3D Viewport and vice versa. Finally, hit that eye icon to hide the lid for now. We’ll finalize the lid once we deal with the body.

Finishing the body

What would you say is wrong or missing from the body? It looks paper-thin, doesn’t it? If only there was a way to stretch each face out or in, and fill in the gaps so it looks solid! So far, you’ve been selecting edges and faces. You can follow a similar workflow to select some faces, duplicate them, and move them around to give thickness to the body. This is tempting, but let’s find an easy way to solidify the body.

For this, you need to enable the Modifiers panel. A modifier is a tool that offers a non-destructive way to change your objects. You’ll get to read about a few of them in the Automating with modifiers section.

There is a wrench icon on the right-hand side near 3D Viewport that is going to let you add modifiers. Here are the steps you must take to give substance to the barrel’s body:

  1. Switch to Object Mode.
  2. Select the Body object.
  3. Open the Modifiers panel.
  4. Choose Solidify from the Add Modifier dropdown.

Modifiers change objects, so even if you are in Edit Mode, working with a modifier will look as if you are in Object Mode for the object you are editing. You’ll discover some of the modifiers in that dropdown list later in this chapter. For now, the following screenshot shows what the Solidify modifier is doing. Most things in Blender come with a lot of values to tweak, but you only need to change the Thickness value in the Solidify options for the time being:

Figure 1.11 – Our barrel is starting to look more solid

Figure 1.11 – Our barrel is starting to look more solid

How much Thickness is enough? 0.03 m or 0.04 m might be a good value. You could pick an industry-standard thickness or choose a value that looks visually appealing. Depending on the type of game you are working on or whether you are creating assets for a client, you can pick what works best for the asset.

A discussion about units

Most of the world is using the metric system these days. However, if either because it’s the default option or a matter of preference, you may have Imperial units set up in your Blender copy. Throughout this book, the Metric system will be utilized. You can find Units as a panel inside the fifth tab from the top on the right-hand side. This tab contains an icon with a cone, a sphere, and what looks like a dot.

Modifiers are very helpful, but you need to get your hands dirty sometimes. This means that there is a limit to what modifiers can do for you. For example, we now need to put metal rings around the body. There is no modifier to do this for you. Nevertheless, we can still take advantage of modifiers as we go. But, first, let’s create some metal rings.

Placing metal rings

The barrel now has some substance, but it’s missing metal rings. Creating another cylinder and sizing it up so that it looks like a ring is too much work and requires precision. There is a simpler method that takes advantage of the barrel’s geometry. You’ll be using familiar methods you’ve already seen: loop cuts, loop selection, and separation.

While in Edit Mode, create a loop cut between the bottom and the first edge loop of the body. For the other loop cut, you’ll be creating the cut in between the top edges and the loop right below it. In the end, you’ll be creating two loop cuts, as shown in the following screenshot

Figure 1.12 – Two separate cuts from both ends approaching the middle section

Figure 1.12 – Two separate cuts from both ends approaching the middle section

You’ve already seen how to select an edge loop: it involved holding the Alt key and clicking an edge. You’ll do something very similar except it’ll be for selecting a face loop. For this, make sure the face icon is clicked in Edit Mode. Alternatively, while in Edit Mode, you can press 3.

When you hold the Alt key and click an edge, you’ll be selecting the faces that are adjacent to that edge you’ve just clicked. It’ll also keep selecting the other faces that are in a similar direction to complete a loop. Try it a few times with horizontal and vertical edges to see how the loops’ direction changes accordingly.

What you must do is select all the faces that make up the two rings that are close to the top and bottom of the barrel. The following screenshot shows which faces should be selected so that you can separate them to form the metal rings:

Figure 1.13 – You’ve got to have something selected so that you can separate it

Figure 1.13 – You’ve got to have something selected so that you can separate it

Once you select the first loop, you can hold down Shift and repeat the previous operation to keep adding more loops to your selection.

Now, you are ready to separate those faces. Hit P to bring up the Separate options and choose Selection. Now, you can rename the newly created Ring object. If you go back to Object Mode, you’ll see that you can select each object individually. Select the ring; you’ll see that the Solidify modifier still exists for this new object too. Isn’t that handy?

The thickness value in the modifier is the same, but what would happen if we changed the sign of that value? If you click the Thickness field, it will let you type in a value. Adjust it so it shows -0.04 m. As you can see, it’s still the same thickness, but in the other direction – it looks like we have those metal rings around the body of our barrel finally!

Now, let’s learn how to add another ring for the middle section. You can follow similar steps to create two more loops, one above and one below the center loop. However, you can do better.

Select the middle edges by conducting an edge loop operation and then triggering the Offset Edge Slide option under the Edge menu or pressing Shift + Ctrl + R. This is very similar to Loop Cut and Slide but it has two major differences. First, this operation will consider an edge as its baseline and move the new edges off in opposite directions. Second, you need to click just once when you are happy with where the new edges will sit. Choosing 0.1 for the Factor value in the operation’s properties might be a good number if you’re having sensitivity issues with your mouse.

We’ll follow a similar procedure: select and separate. In face edit mode, you will use a combination of Alt + Shift by clicking one of the vertical edges sandwiched between your new loops. After you separate the middle faces, you’ll be left with an important decision: should you rename your new object and invert the direction of thickness in its modifier just like you did for the upper and lower rings? In essence, you want your new object to join its fellows. That’s exactly what you’ll do next but with a clever trick without repeating yourself.

Which mode?

During the modeling process, there are times when you’ll need to edit parts of your model. In this case, being in Edit Mode will be necessary. However, when you separate chunks from your models, you’ll most likely want to go back to Object Mode to do something with this new object. So, going back and forth between these two modes will be necessary and feel natural after a while.

In Object Mode, first, you must select the middle ring you have just created. You don’t need to rename it; you’ll see why shortly. You must add one more object to your selection by holding Shift and clicking the ring in 3D Viewport. Make sure your last click is on the ring object you created a while ago. The order of clicks matters at this point. The last object you interact with will be considered as the active object by Blender. It will be marked with a yellow outline compared to orange outlined objects, which are part of the selection but not considered active objects.

Once you have your rings selected in the correct order, you must join them by pressing Ctrl + J. Did you notice what just happened? Let’s break it down:

  • You can no longer see Body.001 in the Outliner
  • The Ring object has accepted Body.001 into the fellowship
  • The Ring object’s Solidify modifier has been applied to Body.001

There are no longer separate pieces since all those separate parts are now considered as one object, as shown in the following screenshot:

Figure 1.14 – One ring to join them all

Figure 1.14 – One ring to join them all

As you get more confident in Blender, you’ll find that you can follow different methods to achieve the same result. There is no right or wrong way, but rather time-saving habits, and you’ll develop your own since every designer has their preferred way of doing things. Sometimes, there are other concerns, technical or artistic, that will limit your workflow. However, as a beginner, you should observe how other artists are creating similar objects. Luckily, there are plenty of examples out there, so learn, experiment, and divert as you go.

Earlier, you had to separate the lid. After that, you made changes to the body and even added rings. Now, it’s time to put a lid on your barrel.

Finalizing the lid

If you hid the lid once you separated it, you can click the eye icon in Outliner to turn it on. You need to do a basic scale operation to put the lid in its place. To achieve this, first, select the lid, and then do the following:

  1. Press S.
  2. Type in 0.96.
  3. Press Enter.

Why such a precise value? Because we’ve been using 0.04 m in the Solidify modifier. So, we should reduce the scale of the lid by 4%. This will save us from the trouble of lining up all the edges of the lid so that they are flush with the inner side of the barrel. If you have been using a different value in your modifier, you’ve got to compensate your scale value in this step so that both add up to 1 in the end.

You’ve done it! With the lid in the right place and looking just below the rim level, the barrel is complete. Check out the following screenshot and compare it to your creation:

Figure 1.15 – A wooden – rather gray – barrel in its glory

Figure 1.15 – A wooden – rather gray – barrel in its glory

If you decide to create this barrel from scratch again, perhaps you can place the upper ring close to the lid, and the lower ring at the bottom. Placing five rings is also a possibility, but you may want to adjust the height of each ring in case the composition looks busy.

So far, you have used one modifier, and it has served you well. Let’s dive into more modifiers and see how powerful they can be.