Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CH22- Game Engine

01-Game Engine

Return to Contents

Game Engine
Blender has the functionality to create interactive video games. The program
integrates real-time motion with physics and logic blocks allowing you to turn objects
into actors and move them around. This process also incorporates character animation
and allows interactive walkthroughs to be created where doors open and close.
The Game Engine is extensive in its application and it is not possible to cover all of
its intricacies in this document. You will have to research and experiment beyond the
scope of this very brief introduction to become proficient.
To get you started and wet your appetite for Gaming follow this very basic example.
At least it will show you how to open the door to the Game Engine.
Begin with the default Blender scene, delete the Cube and add a UV Sphere. Gaming
is a form of animation therefore as with all animation it is best to keep animated
objects with a low vertex count. To keep things simple the default UV Sphere will
suffice.
In the 3D Window Tab into edit mode with the Sphere
selected and grab ons single vertice on the side and make a
pointer as shown in the diagram. This will give an indicator
showing which direction you are pointing when moving
around. The Sphere with the pointer will be our Actor.
Vertices Grabbed and Moved
To form a Pointer

Go to the Information Window header and change the screen


arrangement from the Default screen to the Game Logic screen.
This arrangement has the Logic Editor Window, 3D Window,
Properties Window and the Outliner Window displayed. The
Information Window header is across the top of the Screen.

The screen is configured for setting up the


Game Engine but Blender is not ready yet. In
the Information Window header change
Blender Render to Blender Game.

With the Sphere selected in the 3D Window go to the Properties Window-Physics


button- Physics tab and set the Physics Type : Dynamic. Note that in doing this the
'Actor' box is ticked indicating that the Sphere is an Actor. If it is not ticked, tick it.
O check if the Sphere is behaving itself and is going to cooperate as an Actor in this
little drama, set the 3D Window to front View (Num Pad 1) and with the cursor in the
3D Window press the P Key. This puts the 3D Window into Play mode (Play the
Game). The Sphere should be seen to descend in the window and disappear out of
sight. Press Esc to return the Sphere to center stage in the window.
You have proved that the Sphere actor is behaving itself. Gravity has taken hold of
the Sphere and caused it to fall. Since there is nothing below the Sphere to obstruct its
motion it falls to infinity. We had better do something to correct this.
Put the 3D Window into Top view and add a Plane to the scene. Scale the Plane up
six times. Go back to front View and move the Sphere up above the Plane. Move to
User Perspective View (Num Pad 0 for Camera View then Num Pad 5 for Camera
Perspective then Num Pad 5 again for User Perspective).

Above the Plane


3D View

Press the P Key to see the Sphere descend and sit on the Plane.

Sitting on the Plane


Game Play View

Press Esc to go back to Object mode.

It is time to tell Blender when and how we want our Actor to move.
In the Logic Editor Window you see the Logic Blocks, 'Sensors', 'Controllers' and
'Actuators'.

The Sensor is what will trigger an action.


Click on the 'Add Sensor' dropdown to see the options.
The Controller is what will control the action
click on 'Add Controller' to see options.
They probably are meaningless.
The Actuator tells the Actor what to do.
Click on 'Add Actuator'
Again meaningless.
This is assuming that you
haven't done this before.

We will make some settings and make something happen to give you an idea how this
all works.
In the Sensors Logic Block click 'Add Sensor' and select 'Mouse'. Our mouse will be
the device we use to trigger the action. If you want to change your mind about this
click on the drop down where it says 'Mouse' and you can select something else. Let's
stick with Mouse.

Where it says 'Mouse Event' in the Sensor panel you select what part of the mouse
will be responsible for the trigger. Click 'Left Button' to see options but stick with
'Left button'.
In the Controller Logic Block click 'Add Controller' and select 'And'. Why? will have
to be explained later.
In the Actuator Logic Block click 'Add Actuator' and select 'Motion'. Motion because
we want our Actor to do some moving about. Leave the Motion type as 'Simple
Motion'. Its not time to go complicated.
In the Motion type there are two slots: Loc (Location) and Rot (Rotation) with x, y
and z values. x, y and z are the axis and the value will give the speed of the action.
Enter 'Loc' y:0.20 which means move along the y axis at speed 0.20. Note this is in
the positive y direction. To move in the opposite direction enter -0.20.
The last step for now is to connect the Logic Blocks. Click on the little black dot at
the RHS of 'Sensor and drag over to the little circle on 'Controller. Do the same
between 'Controller' and 'Actuator'.

Connections

Time for a test run. Put your mouse in the 3D Window and press 'P Key' (Play the
game). Give your mouse LMB a click. Just a click. You will see the Sphere in play
mode move. It may not be in the direction of the pointy bit on the Sphere but that can
be adjusted. If you hold LMB down the Sphere will continue moving and fall off the
side of the Plane and disappear into infinity. Press 'Esc' to end the game.
We will add a few more controls.
Adding controls ( Logic Blocks ) soon fills up the Logic Editor Window so to save
space you can click on the little triangles at the upper LHS of the panels and collapse
them. Click again to expand

Add more Sensor,s Controllers and Actuators as shown below taking particular
attention to the values in th Motion Actuators. Do not forget to connect them
together.
Motion Actuator Collapsed

0.20

Left button
Right Button

0.15

Middle Button

With the controls set as show above you can drive the Actor around the Plane. Play
with the Mouse buttons and you will soon get the hang of it. Note the Sphere only
rotates in one direction. You can add another set of controls to rotate in the opposite
direction. Maybe change the Mouse sensor to Keyboard and use the A an S keys for
rotation. You could change all the Sensor controls to Keyboard and use a pattern of
keys.
The foregoing is about as simple as it gets so its over to you to research and
experiment.

You might also like