Learning the basics of using the Blender Game Engine
Now that the basics of Blender have been covered, we will now focus on the GE related features of Blender.
We will start with the most important key in Blender, the one that starts the GE.
Move your mouse cursor over the 3D scene, and press P to begin playing.
Congratulations, you have just played your first game within Blender! How easy was that?
As we haven't told the GE to do anything yet, nothing will occur within the scene. Press Esc to return to Blender.
Setting up the default scene
Before we start, reset the scene in Blender to get back to the defaults.
This can be done be either of the three methods below:
- Selecting the File -> New menu and clicking on the Erase All option.
- Press CtrlX and click on the Erase All option
- Quit Blender (CtrlQ - just Q in 2.42 or older) and restart it.
It's time to see how well you can use Blender, using the information you learned from the previous section.
Set up the 3D view in Blender to look like in the image.
To do this, you will need to carry out the following tasks...
- Rotate the scene using the middle mouse button MMB
- Change the view into perspective mode using View -> Perspective
- Add a cube and a lamp (assuming you deleted them previously and that they are not part of the default scene when Blender loads a new file).
A very useful keypress sequence when working with the GE
One useful keypress to remember when working with the Blender GE is the one that maximizes the current 3D window.
Move your mouse over the 3D window, and press Ctrl↑ (or Ctrl↓). This will make the current window scale to the full size of the Blender area. If you press Ctrl↑ again, the window will be restored to its previous size and location.
Go ahead and practice this now:
- Maximize the 3D window using Ctrl↑
- Press P to play the current scene within the GE (nothing will happen)
- Press Esc to return to modelling mode
- Restore the 3D window to it's original size again using Ctrl↑.
The animated image below shows the effects of using the Maximize/Restore keypresses within the default Blender screen setup.
Choosing the correct Shading Mode (or Draw Type) for the GE
Enter GE mode again by moving over the 3D panel and press P. You will notice that the scene within the GE appears flat. Press Esc to return to Blender.
Blender has a number of draw types for the viewport that are useful for different tasks. The panel to change the current shading mode is shown below...
The image below show how the basic scene looks in the GE, in the various Shading Modes
- Solid mode doesn't take into account the lights in the scene
- Shading mode takes into account the lights in the scene
- Textured mode takes into account the lights in the scene, and also shows any UV/Image textures live in the viewport. This will be as close to the actual in-game view as you can get, and should always be selected when you start a new GE project.
The best draw type for the GE is Textured. Select this Textured draw type from the list, and press P again. You will notice that the lighting affects the environment within the GE now, making it look more realistic. Always remember to set this option to Textured if you play your scene in the GE and it appears flat.
The Main Game Logic Panel
Below the 3D window, you will see the panel that contains many different buttons for controlling different aspects of Blender.
This panel is where you will control what will happen within your game.
Blender uses a visual click-and-drag system to create basic game interactions. This allows the GE to be used by 3D artists who may not have access to a coder. Blender also uses a programming language, Python, which can be used to create more complex game interactions.
For the purposes of this tutorial, we will focus on the visual system for creating games. When you have grasped the basics of using the Blender GE, you can then follow more advanced tutorials showing how to implement Python scripting to create more complex games.
Visually controlling the GE - Sensors, Actuators, Controller Logic Blocks
The GE system uses Logic Blocks as a visual way to set up interactions within the game. These logic blocks can be connected together visually to allow for complex game actions to take place.
There are three different types of Logic Blocks - Sensors, Controllers and Actuators - each with a number of different sub-types.
A Sensor will detect some form of input. This input could be anything from a keypress, a joystick button, or a timer that triggers every screen update (or frame) of the game. By default, Blender calculates 60 game frames every second. You can change the frame rate, mist settings and the gravity in the world buttons, physics panel (Mist, Stars, Physics).
Controllers are used to link Sensors to Actuators.
They allow for some more complex control over how sensor and actuators interact with each other.
An Actuator will actually carry out an action within the game. This can include moving an object within a scene, playing an animation, or playing a sound effect.
Setting up a basic Sensor, Controller, Actuator Logic Block sequence.
We will now set up a very basic system within the game panel by adding and connecting a sensor, controller, and actuator together.
Make sure the Game Logic panel is visible (click on the purple pacman in the Buttons window) and re-select the cube within the 3D scene
Below each of the 3 main sections, you will see the selected object's name and an Add button. Click this Add button once for each of the 3 sections: Sensor, Controller, and Actuator.
We will now connect this system together. Click and drag from the socket (small circle) at the end of the first sensor to the socket at the start of the controller. Then click and drag from the socket at the end of the controller to the socket at the start of the actuator.
The animating image below shows the steps involved in setting up a simple Sensor, Controller, Actuator chain and connecting them together.
Press P to now play the game. You will notice that, although we have added some control to the GE, nothing seems to happen again. This will be explained in the next section. Press Esc to return to Blender.
Breaking down the events in the GE system
We will now look into what is happening with our newly created GE system.
The sensor is an Always timer. This will send out a signal every single frame, so the linked controller will be activated continuously thoughout the duration of the game.
The controller is an AND. When it has just one active sensor input (like in the current case), it will automatically call the connected Actuator.
The Actuator controls the Motion aspects of the selected object.
Because of the Always sensor connected to the controller, this actuator will be called every single frame.
If we press P now, it is being called every single frame, but because all of the values are set to zero in the Motion actuator, the object will not move within the GE. Press Esc again to return to Blender.
--Mal_CanDo 17:00, 18 August 2006 (GMT)