Your first 3D Game with Blender3D

This tutorial is about the very basics of Blender3D. It assumes that you never used Blender3D and it doesn’t require any special skills. Through this tutorial I’ll to show you every single step you need. If you feel it’s too slow just skip some steps.

Made with: Blender3D v2.62, February 2012
Duration: 30 – 90 minutes (depending on how quick your fingers are)

What we’ll get at the end of this tutorial

The play scene is a field full of holes. Your character (we’re gonna use a sphere for the character) should avoid the holes while it collects some objects spread on the whole playground.

Following steps will be introduced

Let’s start

- Start Blender3D. The default scene is there with a cube, a lamp and a camera. The three arrows (red, green, blue) out of the cube refers respectively to the space axis “x, y, z”.

Create the ground

- In the 3D view, select the cube with RMB (right mouse button) -> It should be highlighted with an orange line

- Push X (on keyboard) -> Confirm “delete”

- Be sure the cursor (the red-white dotted circle) is in the world origin with Shift-C (the cursor can be replaced with LMB click)

- Push the space -> Pop-up search appears -> Enter “plane” -> Confirm “Add plane” -> A plane should be added to the scene at the position of the cursor

- Re-size the plane with pushing “S, 5, then RETURN” in your keyboard
- Switch to the “Edit Mode” with TAB key

Edit Mode is where you can see and move every single vertex, edge or face of a 3D object separately. In this mode you aren’t able to select other objects

- Divide the plane with W -> Confirm “Subdivide” -> F6 -> Change “Number of Cuts” to 9
- The plane is now divided by 10×10
- Switch to Face Select Mode with CTRL+TAB -> Confirm “Face”

There are 3 Select Modes: Vertex, Edge and Face select mode

- Switch to the down-view with numpad-7 (if you’re using a laptop, you can emulate the numpad)
- Select faces with RMB (hold SHIFT down for multiple selection): Select about 2 or 3 faces in every row. The selected faces will be the holes your character should avoid, so don’t forget to leave ways between the holes
- Switch to the side-view with numpad-3
- Now we gonna make the holes by extending the faces already selected: Enter E, then “-1″ -> The faces are being extended in the inverse direction of their normal vectors (Each hole have the form of cube with an edge of 1 Blender unit)

- We’re done with the ground. Leave the “Edit Mode” to the “Object Mode” with TAB

Create the character and move it

- Be sure the cursor (the red-white dotted circle) is in the world origin with Shift-C

- Push the SPACE-bar on keyboard and tap “sphere”, then confirm “Add UV Sphere”

- The diameter of the default sphere is 2 blender units. Rescale it to 0.5 Blender unit (S, 0.25, RETURN), so it could fall into a hole

- Move the sphere to a position where it can start the game e.g. (x,y,z) = (4.5, -4.5, 0.5) by tapping G, X, 4.5, RETURN, G, Y, -4.5, RETURN, G, Z, 0.5, RETURN

Let’s recapitulate: G to Grab, S to Scale, R to Rotate, X to Delete, SPACE for quick search. Shortcuts could not function if you change the Mode or if the Mouse-Cursor is over the wrong sub-window

- In the default Blender file, the horizontal sub-window in the bottom is for Timeline. Click on the “Watch icon” and switch to “Logic Editor” (You can make this sub-window bigger)

The Logic Editor is divided in 4 columns: Properties, Sensors, Controllers and Actuators. You can add logic briks by clicking on the Add-buttons and make logical connections between them by binding the dots beside the blocks. Logic bricks are added to the selected object!

The blocks (or “bricks”) represents preprogrammed functions which can be tweaked and combined to create the game/application. The system is broken up in three parts: sensors, controllers and actuators. Sensors sense when things happens, such as a collision, a key press, mouse movement. Sensors are linked to controllers, which compare them and activate actuators. Source: Blender.org

- Open a sub-window for Info e.g. in the upper horizontal sub-window (Just click the icon in the left) and change “Blender Render” to “Blender Game” (Blender Game Engine is used as a renderer)

- In the subwindow (Properties) at the bottom on the left, change “Physics Type” to “Rigid Body” (Object type with rotations).

- Let’s make the cube move forward while the UP-ARROW is hold down:

  • Add a “Keyboard”-Sensor, an “AND”-Controller and a “Motion”-Actuator
  • In the “Keyboard”-Sensor, click in the parameter field “Key” and press the UP-ARROW
  • The “AND”-Controller should not be changed (It’s just used to pass the signal to the actuator)
  • In the “Motion”-Actuator, in the second variable of the Force-parameter (that’s the Y-Coordinates of the position) tap 1
  • Uncheck the “L” (local coordinates) in front of the Force-parameter, so the force will be applied along the world axes (and not relative to the sphere local directions, which are not constant)
  • Make connections between Sensor and Controller and between Controller and Actuator (Click a dot with LMB and draw a line to the targeted dot)
  • Press P in your keyboard to switch to the Play-mode (Be sure that the mouse-cursor is over the sub-window of the 3D View) and push the UP-ARROW -> The sphere should be moving in the Y-Direction

- Now do the same to make the sphere move backward (Y: -1) with the DOWN-ARROW, to the right (X: 1) with the RIGHT-ARROW and to the left (X: -1) with LEFT-ARROW (Add a sensor, a controller and an actuator for each movement)

- Test your work in the Play-mode

Create the objects to collect

We’re gonna add some cubes to be collected.

- Be sure the cursor (the red-white dotted circle) is in the world origin with Shift-C

- Add a cube: Push SPACE then tap “cube” and confirm “Add Cube”

- Scale it down (S, tap “0.2″, RETURN)

- Rotate it 45 degrees around the X-axis and 45 degrees around the Y-axis (R, X, 45, RETURN, R, Y, 45, RETURN)

- Move it up to e.g. z=0.5 (G, Z, 0.2, RETURN)

- Let’s give this collactable a permanent rotation movement:

  • Add an “Always”-Sensor, an “AND”-Controller and a “Motion”-Actuator
  • Make connections between them
  • Change the third variable of the Rot-parameter to “1″ and uncheck the “L” (That makes the Cube rotate one degree per frame around the world Z-axis)

- Now if you press P, the cube should start rotating automatically

- We should make the cube disappear when it get touched by the sphere:

  • First of all, add a “Collision”-Sensor, an “AND”-Controller and an “Edit Object”-Actuator to the cube
  • In the sensor-brick, tap “player” into the “property”-parameter (The cube will be checking if it’s colliding with an object having the property. Therefore we’ll add later a property named “player” to the sphere)
  • In the actuator-brick, change the parameter “Edit Object” to “End Object”
  • Add a property to the cube with the button “Add Game Property” in the logic editor and name it “cube” (This property will be used later)
  • Select the sphere, add a property to it and name this property “player”

- Let’s duplicate the cube, and put the duplicates around the play area:

  • Switch to down-view with 7 and adjust the view to be able to see the whole play area (Zoom in/out with CTRL+MMB). Switch to Wireframe-view with Z (to distinguish the holes)
  • Select the cube with RMB (if it’s not selected yet). Grab it to a position where the sphere can reach it (G, move mouse, RETURN)
  • Duplicate the cube with SHIFT+D
  • The duplicate position is currently assigned to the mouse position, so move the mouse and confirm position with LMB

I made 5 duplicates.

Now turn on the play mode with P to check what you’ve done

End of the Game

After collecting all of the cubes you shall be informed about that with a panel telling you that “YOU WON”. Otherwise if you fall before collecting all the cubes, the game will be restarted.

Let’s start with the winner case:

- Select the sphere with RMB

- Add a property, name it “collected” and change its type to “integer”

- Add a “Collision”-Sensor and set its property parameter to “cube”

- Add an “AND”-Controller

- Add a “Property”-Actuator, set its Mode to “Add”, Property to “collected” and Value to “1″ (this will add 1 to the property “collected” each time the sphere collides with a cube)

- Make connection between the logic bricks

- You can debug property information in the play mode:

  • Check the information icon of the property
  • In the sub-window “info”, “Game”, check “Show Debug Properties”

Now switch to play mode with P. The property “collected” of the sphere object is displayed in the 3D View. Start collecting the cubes -> “collected” increases on each collision with a cube

- The second part of this system is launched when the property “collected” reaches 5 (the number of the cubes):

  • Add a “Property”-Sensor, set its property parameter to “collected” and its value to “5″
  • Add an “AND”-Controller
  • Add a “Scene”-Actuator and change its mode parameter to “Add Overlay Scene”. The scene parameter should be set later to the name of the scene containing the text “You Win” (We will create this scene later)
  • Add another “Scene”- Actuator and change its mode to “Suspend Scene” and its scene parameter to “Scene” (That stops the play scene and suspend the controls)

- Now we should add the missing scene:

  • Press SPACE button, tap “scene”, confirm “New Scene” > “New”
  • Be sure the cursor is in the world origin with Shift+C
  • Add a Text to the new empty scene (SPACE, tap “text”, confirm “Add Text”)
  • Switch to Edit Mode with the TAB
  • Erase the default text with the BACKSPACE then tap “You Win”
  • Switch back to Object Mode with TAB
  • Be sure again the cursor  is in the world origin
  • Add a camera
  • Move the camera in a way that the text “You Win” is centered in the camera view (switch to/from camera view with 0)

- In the sub-window “Outliner” (at the top on the right) switch to our first scene named “Scene”

- Select the sphere and change the scene parameter of the “Add Overlay Scene” to “YouWin”

- Move the camera to a position where the whole game area is visible in the camera view and the X-axis of the world is horizontal to the view (so the Arrow-keys correspond to the movements of the sphere: Up to forward, left to left, etc.)

All what is missing now is a reaction when the sphere falls into a hole or from the plattform! Let’s make a simple restart option:

- Make sure the cursor is in the origin of the world (SHIFT+C)

- Add a plane and resize it to 6 times (S, 6, RETURN). A little bigger than the play area

- Move it 0.5 unit down (G, Z, -0.5, RETURN)

- In the sub-window “Properties” go to “Physics”

- Set “Physics Type” to “Static”, check “Gohst” and “Invisible”

- In the sub-window “Logic Editor”:

  • Add a “Collision”-Sensor with property “player”
  • “AND”-Controller
  • “Scene”-Actuator with Mode set to “Restart”

Now you can test your game and try to improve it.

We’re done with this tutorial. That was a simple game without use of a scripting language, thanks to the preprogrammed logic bricks of Blender3D. If that was helpful to you, be sure to leave a comment.

Download

Download the completed Blender file of this Tutorial

  • dario90
    #1 written by dario90  1 year ago
    1

    Hello, I would like to watch a videotutorial about 3D game programming with OpenGL and how I can run a Blender3D animation with an application developped by me with OpenGL. I hope you make a new videotutorial please.

    Thanks, I’m sorry for my english. Bye.

  • You may use these HTML tags: <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong>

  • Comment Feed for this Post
Go to Top