Home Game Development Blender Game Engine: Beginner's Guide

Blender Game Engine: Beginner's Guide

books-svg-icon Book
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    1. Things You Need to Know
About this book
Blender Game Engine is the part of the Blender 3D editor used to create actual 3D video games. It's the ideal entry level game development environment because you don't even need to learn to program. Create a complete game using Bender's innovative logic bricks."Blender Game Engine: Beginner's Guide" is the ideal introduction to game development. Using only logic bricks, the reader will create a complete game in Blender. By the end of the book the reader will be able to use their skills to create their own 3D games.
Publication date:
September 2012
Publisher
Packt
Pages
206
ISBN
9781849517027

 

Chapter 1. Things You Need to Know

The Blender Game Engine (BGE) is one of the most interesting parts of Blender. This book will help you to get started and make games by modeling low poly objects and animated interactive characters, and use them in the Game Engine with basic controls and more. To learn the BGE, you'll need to learn a Node Editor which provides you with an easy-to-use visual interface (logic blocks) to design games without requiring any knowledge of programming.

The Node Editor has a visual way to set up Composite and show the results. Logic blocks can be connected, which together allows you to create visually complex results. There are three different types of logic blocks in the BGE: sensors, controllers, and actuators. Each of these has a different number of sub-types. Using this system, you can make a character respond to your keyboard input events or set up some basic Artificial Intelligence (AI) behavior for your enemy characters, objects, or environments of the game.

To make games with Blender, we can begin in the section called Logic Editor (sections in Blender are called editor types). Game Logic is what causes anything to happen in the game. The blocks (or "bricks") that you can see represent pre-programmed functions that can be tweaked and combined to move the player, interact with the world, change the level, and more. In short, it helps you create the game.

At the beginning, we do not need cool models, only a cube (by default, Blender shows it) to represent our player in order to move in our 3D environment. We will learn how to move it and how it collides with a wall (plane). If we do that, we can then proceed to substitute our poor model (a cube) and wall for a cool character and good environments. Are you ready?

This book assumes that you haven't had any, or very little, experience in using Blender, so we will go through these chapters step-by-step.

In this chapter we shall:

  • Find out about the Interface of the Logic Editor
  • Learn how to use the Logic Bricks Editor
  • Start the Game Engine
 

Things you need, and things you don't

The basic equipment that you need to make a Blender game is the Blender program, which you can download for free from its official page at www.blender.org. It would be better to use the latest version, but it is not necessary. You can make an executable game and then others could play your game without needing to install Blender. Blender runs in most of the common operating systems such as Windows, Linux, and Mac. If you have a standard computer, you have the basic requirements to install a copy of Blender.

If you have never used Blender before, I would recommend you to spend a bit of time reading the documentation and try to do some tutorials provided on Blender's website. You might also find it useful to spend time reading some of Blender's beginner tutorials on other websites. This will help you learn techniques of Blender that we don't show in this book. These friendly websites will answer some of the basic questions that you might have about how to use Blender in modeling, texturing, animation, and others that we do not cover completely.

Surprisingly, all of the information provided on these websites is necessary, but not at this moment, not for your first Blender experience. Creating a lot of (Blender) games will surely help improve your knowledge. Blender uses a visual click-and-drag system to create basic game interactions. This allows the BGE to be used by everybody, including those who may not be programmers. Blender also has a programming language, Python, which can be used to create more complex game interactions. For the purposes of this book, we will focus on the visual system for creating games only. When you have learned the basics of using the BGE, you can then follow more advanced tutorials which show you how to implement Python scripting to create more complex games.

As you may know, Python is a programming language. Python can be used as an extension language for existing modules and applications that need a programmable interface. It has the design of a small language with a large standard library and an easily extensible interpreter. Most Python implementations can function as a command-line interpreter, for which the user enters statements sequentially and receives the results immediately.

Python is essential to make better presentations with the characters, animations, and the rest of the game, but it is not necessary that you use it. Someone can help you in the parts where you do not know enough. The only thing you need to know is how you use logic bricks. Later, you will improve on the rest. Blender's popularity and faithful following has been growing rapidly since its first release in 1998. This has led to a large number of individually-run websites focused on Blender. Go to the official Blender site to see a selection of the websites dedicated towards helping the community.

 

Time for action — start using the BGE

Let us start and open the Blender program. Closing the splash screen then reveals Blender's default scene that is composed of a main view surrounded by other panels. The main area in the center of the screen is the 3D View, as shown in the following screenshot. By default, this contains a cube as I had mentioned earlier in the chapter.

Time for action — start using the BGE

We can change the default view and choose the Game Logic view. To do this, go to the top menu bar and click on the icon next to Default. The drop-down menu will show several preset views, as shown in the next screenshot. We can choose the one that interests us, which right now, is the Game Logic view.

Time for action — start using the BGE

What just happened?

Blender's flexibility with windows lets you create screen layouts for different tasks, such as Animation, Compositing, Default, Game Logic, Scripting, UV Editing and Video Editing. It is often useful to be able to quickly switch between different environments within the same file. For each task, you need to set the stage. In this example, we selected the Game Logic view for our main purpose of making games.

Use the window controls to move frame borders. When you have a layout that you like, and wish to use it as your favorite layout, click on the + button to save the layout as a new preset layout template. Obviously, if you want to delete it, click on the X button.

 

Exploring the interface of the Logic Editor

Alas! There are so many panels and everything seems so confusing. Do not worry, my first impression was the same. However, by the end of this chapter, you will be familiar with most of the on screen elements. When you create a game with Blender, you do not work with only one editor type. But without Logic Editor, it is not possible to make a game.

Knowing the interface of the Game Logic view offers insight into how the Logic Editor works and prepares us to make complex connections in our game truly interactive.

The Game Logic layout is divided into areas by default, each of which has a particular function or purpose, depending on what the user is doing at that time. There are Header areas in each display editor type. Using these headers (pointed out by the arrows in the next screenshot) we can swap between different editor views. We will focus on the bottom display called Logic Editor (bottom left header).

Exploring the interface of the Logic Editor

Tip

If you want to zoom in/out of the Logic Editor work area, you must press MMB (middle mouse button) and move it. If you want to pan work areas click Shift button + MMB. Choose Ctrl button if you have Mac OS

The Blender Game Engine uses logic bricks (a combination of sensors, controllers, and actuators) to control the movement and display of objects in the engine.

  • Sensors sense events, for example, a key press or mouse movement. Sensors are linked to controllers which compare them.
  • Controllers check (true or false) and combine these pulses to trigger the proper response and activate the last group: actuators. They can also be thought of as conditional rules.
  • Actuators initiate their functions when they get a positive pulse from one (or more) of their controllers.

We will explain shortly these three parts of logic bricks and set up a very basic system within the game panel by showing how to use a sensor, controller, and actuator.

Tip

The list menu of an object's logic is only visible when the object(s) are active (shown in white in the outliner panel). Be sure the cube is selected (if not, click on it in the 3D View with the right mouse button).

 

Time for action — exploring the logic bricks world

All objects have two options, one of which is a label with their name (in this case Cube), and the other a button labeled Add Sensor. The Add Sensor button adds a new sensor to the object. The following steps will help you in exploring the world of logic bricks:

  1. Select the Cube with RMB. Click on Add Sensor and select Keyboard as the sensor in the sub-menu listed:
    Time for action — exploring the logic bricks world
  2. Be sure to select the cube with RMB to operate with logic bricks. Press the D key or Right arrow key in the blank cell with no label if you want to move the object, for example, to the right. The key that you press will be assigned to the sensor. This is the active key, which will trigger the positive pulse. Click inside the button again if you want to change or un-assign the key:
    Time for action — exploring the logic bricks world
  3. Next, click on Add Controller. The first controller in the menu is called And. This is the default type when you create a new controller. It can be used to simply pass a Sensor event directly to an Actuator (as shown in the next point):
    Time for action — exploring the logic bricks world
  4. Next, click on Add Actuators, and choose Motion:
    Time for action — exploring the logic bricks world
  5. Now, change the value of x axis to 0.20 in Loc (Location). The three grey boxes in each row is the motion on the x, y, and z axes (in that order). If you want a diagonal motion, add values to all of the axes at the same time. If you want to rotate the cube, enter 0.20 in Rot (Rotation) of x axis:
    Time for action — exploring the logic bricks world

    The cube jumps the number of blender units that we input, this can cause objects to go through and around our scene.

    Tip

    The L button switches whether the motion will be added to the local or global axis. Local axis is the object's own axis. This is the most common option and is the default. With the global axis, the cube movement can be aligned with the axis of the world.

  6. We will now connect this blocks system together. Click-and-drag from the socket (small circle) at the end of Sensor to the socket at the start of Controller:
    Time for action — exploring the logic bricks world
  7. Then click-and-drag from the socket at the end of Controller to the socket at the start of Actuator:
    Time for action — exploring the logic bricks world

    In this example, the sensor is responsible for moving the cube forward if we push the Right arrow key.

  8. Press the Start button to play the game in the Properties Scene panel:
    Time for action — exploring the logic bricks world

    The cube will not move automatically. Press the Right arrow key, and it will start to move forwards. When you stop pressing the key, the cube will stop moving. Keep the key pressed to move the cube further. Press Esc to return to Logic Editor of Blender.

    If you're happy with what you've seen, click on the Start button again, you can do it as often as you like.

    Tip

    Change the size of the view in the desired panel by moving the cursor near the limits of the header menus, moving horizontally and then vertically.

    You can also press the Ctrl + Up arrow key to get a completely maximized view (be sure you click on the 3D View panel before doing so).

What just happened?

Great! You just accomplished the three parts of logic bricks, and there is a connection among them. Let's review how to do that and we will be ready to understand the parts!

  • Sensor

    The Keyboard sensor is for detecting keyboard input. The first blank cell is for single key presses. We pressed the D Key, or the Right arrow key, to move in the x axis of our cube. Sensors are grouped by objects, with every selected object appearing in a list and under each object are its sensors. It is possible to filter them if we check/uncheck which sensors are viewed. We can select which sensors to be viewed from the following options:

    • Sel: Shows all of the selected objects' sensors
    • Act: Shows only the active objects' sensors
    • Link: Shows the sensors which have a link to a controller
    • State: Shows only those sensors connected to a controller of the current state

    But for the moment, let us leave them as they are.

  • Controller

    The controllers are the bricks that collect data sent by the sensors.

  • Actuator

    The actuators initiate their functions when they get a positive pulse from one (or more) of their controllers. They set an object into motion, for example, rotation.

    Simple Motion applies motions in our cube without frictions. If we need a character with resistance, we need to choose Servo Control, which consists of a servo controller that adjusts the force on the object in order to achieve a given speed, and hence the name Servo Control. For the moment, Simple Motion is right.

Of course, the cube has got only one interactive key, and will go ahead if we push the Right arrow key in the keyboard. However, this just introduces us to the fundamentals of the Blender Game Engine. You just need to try, test, and modify it. It is easy, isn't it?

Hey! We are finally programming video games! In some aspects, this is similar to being a computer programmer.

By adding more logic, we are ready to continue making a game. But first, let us try to finish an entire movement of our cube so that you can move freely in our private 3D scene.

 

Time for action — moving the cube

To add more movement to the cube, perform the following steps:

  1. Press the Ctrl + Up arrow key to work with the maximized area of the Logic Editor panel. We will be using three more keyboard sensors, let's start creating them.
  2. We have a D or Right arrow key connected. Let's do the rest. Add a new sensor called Keyboard again and press the Left arrow key in the blank cell as shown in the following screenshot:
    Time for action — moving the cube
  3. Add a new Keyboard sensor again and press the Up arrow key as shown in the following screenshot:
    Time for action — moving the cube
  4. For the last one of the keyboard sensors, press the Down arrow key as shown in the following screenshot:
    Time for action — moving the cube

    As seen in the previous screenshots, sensors have been closed by clicking on the triangle on the left-hand side of the header to get more space. But we realize that Keyboard1, Keyboard2, and so on do not mean much to us. I recommend renaming Sensors in order to make them accessible and readable in an easy way when we have more sensors in the list.

  5. Just click on the field that displays, for example, Keyboard3, and rename it to Key Down. Use this process to rename the rest of the Sensors:
    Time for action — moving the cube
  6. Add all of the Keyboard sensors to a controller each, as we did for the first one, by clicking on Add Controller, and select And as the controller and connect them each, one to one:
    Time for action — moving the cube
  7. Add three more Actuators by clicking on Add Actuator and selecting Motion.

    Change the value in each cell as shown in the next screenshot. In this case, the left key is assigned -0.20 in x axis and the up/down keys are used for the rotation of our cube, the value of the up key is 0.20 in the Rot Z axis and -0.20 for the down key in Rot Z.

    Time for action — moving the cube

    Note

    Of course, we need to rename all our active Actuators, similar to how we had renamed our Sensors (as shown in Step 5). Spend a little time renaming them to, for example: Move Right, Move Left; Rotate Right and Rotate Left.

    At the end of this exercise, our cube should move while we press the key correctly. But wait! The last step is to connect all of the bricks together.

  8. Drag-and-drop to connect all of them (as shown in the following screenshot) and just press the Ctrl + Up arrow key (minimize the Logic Editor area) and finally press the Start button:
    Time for action — moving the cube

    Tip

    If you wish to maximize the 3D View area, press the Ctrl + Up arrow key after having clicked on the 3D View area with the Left mouse button as shown in the following screenshot:

    Time for action — moving the cube
  9. For starting the Game Engine, press P. You will be able to move your cube around as shown in the following screenshot:
    Time for action — moving the cube

    We can move our cube around the screen. That's fantastic!

What just happened?

We managed to easily and intuitively work with Logic Editor. We created an interaction with our character by adding the following:

  • Sensors to recognize the keyboard
  • Basic controllers to link the actuators to the sensors
  • Actuators that will move the cube, by following the inputs from the keyboard added as sensors

As you have seen, many operations with logic bricks are repeated. But in the end, we change a numeric value of the actuator, which facilitates the learning by repetition so that it's not difficult to understand how the other bricks work.

We learned how to move our cube in the 3D scene by connecting logic bricks. It is as easy as giving orders by using the keyboard. You could increase the mobility options if you have more buttons to press.

Pop quiz — exploring the interface of the Logic Editor

  1. If you want to create a jump motion, which local axis must you change?
    1. x
    2. y
    3. z
  2. Which option do you choose if you want to go in the opposite direction of the x axis while rolling?
    1. Subtract the X value
    2. Add a value less than X
    3. Change the Y value
  3. Which cell modifies the values of rotation?
    1. Loc X, Y, Z
    2. Loc in X or Y or Z
    3. Rot X, Y, Z
    4. Rot in X or Y or Z

Certainly, you do not need the answers. It is so easy to watch the result instantaneously that it is much better for you to prove all your answers and change if the result does not satisfy you.

Have a go hero— doing more

You know how easy it is to change the values of our cube. If the rotation is slower than you like, change it! And find the best result for you.

If the screenplay is empty and you need another object for reference, just add other cubes in the same scene. Select Add | Mesh and choose Cube, scale it by pressing S and move it around in your scene. Repeat this twice and try to move your cube characters without touching them. This is a good practice to see how you play games with the keyboard.

Note

Point of active view

We did not discuss the view that we used in this chapter. In the games, we normally have various cameras. We will learn how to change this in Chapter 5, Gameplay. For the moment, the active camera is the active view in our 3D View. For better understanding of how to move the cube, the top view is the active view of this game exercise.

 

Summary

We have taken the first step in using the Blender Game Engine. It has not been so hard, has it? We have learned enough in this chapter, all of the secrets of logic bricks have been shown to you. You will find that you will use these same connections for setting up your first level of the game and again in your future projects of Blender Game Engine.

This chapter has covered a lot about the logic brick's world:

  • We have learned the basics of the interface of Logic Editor. There are three parts of logic brick: sensors, controllers, and actuators. Each one has a sub-menu to choose the action that we want.
  • We have seen how easy it is to connect them together. Draw a line between particular socket-like nodes, we can test all of the connections, a lot of trials, and perhaps some errors.
  • Finally, we finished the whole movement of our player, a simple cube, making all of the necessary bricks move around, connecting and renaming them for best comprehensive multiple bricks.

We even play in the same point of view, but later we will change and it will improve our game.

Now, we are ready to forget the cube and create the character of our video game. If you are a good 3D modeler, you can choose to create your own character. Or to make it easier, get free characters from web libraries because you know that you can add this game logic to any model in Blender (no matter what shape or size it is), and it will move around just like the cube that we have learned to move!

Latest Reviews (3 reviews total)
La collana Beginner è uno strumento valido per tutte le persone che vogliono cominciare a sviluppare: che sia un gioco, un nuovo linguaggio o altro. La possibilità di cominciare da zero un gioco in Belnder permette a chiunque abbia un minimo di conoscenza nella programmazione, di apprendere le tecniche di sviluppo del tool descritto nel libro.
Blender Game Engine: Beginner's Guide
Unlock this book and the full library FREE for 7 days
Start now