blender www.blender.nl
this document is online at http://www.blender.nl/showitem.php?id=14
 The Blender Game Engine Beginner  About the new features
2000 07 25 
  Bart Veldhuizen  id14 
Introduction
This tutorial explains the basic concepts of Blender 2.1 It assumes basic knowledge of how to use Blender - these have not changed much since Blender 1.8 and the old tutorials are still applicable (although sometimes a button may have been moved to another location).

If you are unfamiliar with Blender, please do the following tutorials first:
  • The Blender User Interface
  • Navigating in 3D Space
  • The Blender Windows
  • Building a Castle


  • Let's start by adding a cube. Remove the default plane and add a cube. Start scale mode and make it large enough to fill the entire screen. We'll use the cube as the scenes floors and walls.


    Let's add a game character now. In top view, add an icosphere with a subdivision of 2. (The higher the subdivision, the more polygons your character will get and the slower your game can become!). In editmode, drag out a 'nose'. This will indicate our direction of movement later on. Moving around with a perfect sphere is rather confusing.


    Press to start the real-time simulation. It just sits there - nothing happens! No wonder, since we have not defined any physics or events yet. Let's do that now.

    Dynamics
    Stop the simulation with . Select your character and go to the Real-time buttons (press ). On the far left you'll see a button labeled 'Actor'.

    An actor is not necessarily the main character in a game. An example of an actor can be an enemy that follows you around the game.

    Select Actor for your character. If you would restart your simulation at this point, still nothing would happen. Let's turn on the physics simulator for this object now: with your character still selected, press 'Dynamic'. ('Dynamic' appears after 'Actor' has been selected).


    Rotate your view a bit (the top view will not show this effect properly) and press . Your character falls to the floor.

    Forces and Materials
    Now let's work on the physics a bit more. First of all there is a global parameter for gravity in the World Buttons window. Add new world settings; a new slider called 'Grav' is now availabe. This is a constant for your world; all the Dynamic objects are affected by it. The standard value is 9.8, which results in a natural gravity-like acceleration of falling objects.

    Now return to the Real-time buttons. For each object, you can define the a number of parameters.


    1) Mass.

    When applying a force, the mass determines the acceleration that an object gets. Higher mass results in a smaller acceleration.

    When you have both large and small objects in your game that interact with each other, be sure to match their relative masses - this will add to the realism of your simulation.

    2) Damp.

    Motion dampening. This is a friction force that always works on your object - both when it touches a floor and when it is free. A good way to describe it is 'air friction'.

    When an object has a Damp value, it will always slow down when there are no other forces working on it

    3) RotDamp.

    Rotational dampening. Like the motion dampening, this affects an object's rotational speed.

    4) Size.

    Blender's current physics engine uses spheres to represent your dynamic objects. This parameter represents the size of the sphere. The collision sphere is drawn as a dotted circle in the 3D window. In most cases, you should try to enclose your object in the collision sphere. If you don't, parts of your object will be able to stick through walls and other objects.

    Set the size value now for your character. The collision sphere will center around the icosphere's object center. To shift the object relative to the collision sphere enter editmode, select all vertices and move them around.


    Let's play with the physics simulator a bit more before we move on. Add a plane while in topview and switch to front view. Create some duplicates and rotate and move them around a bit until you have a situation like this:


    Press and watch your character fall down the different planes. Something still is not right here: whenever it hits a plane, it immediately sticks to it and starts to slide down. To fix this, we'll have to tweak the dynamic material properties of the planes.

    Materials
    Besides color information, each material now also has dynamic properties; using these you can define different forces that define the interaction between the objects that carry this material and dynamic objects.

    Add a new material to one of the planes now and select the 'DYN' button.


    As the first test, let's play a bit with the 'Restitut' value. This value determines how much of the object's kinetic energy is returned to the object after it has a collision. In other words: this value defines the 'bounciness' of your material. Set it to one now. Select the plane directly underneath your character and clear its rotation with to level it. Press to play your simulation.

    You would expect it to keep bouncing, wouldn't you? Wrong - remember the 'Damp' setting? The dampening slows down your sphere a little all the time. That is why it bounces less and less high. Select your character and set 'Damp' to zero. Press again and watch it bounce ad infinitum.

    Take a look at this example: the planes have been placed to keep the ball bouncing around for quite a while:

    Download:
     bouncing.zip
    Reset the 'Damp' value to 0.04 now. The next thing we are going to try is called 'Fh'. This is a term that has been borrowed from physics where it means a force in the vertical direction. It works the same in Blender, but here we also have to define a region of influence. This region of influence is controlled by Fh Dist. This value creates a 'cushion' around your object in which the Fh force will be active.

    Try the following: set Fh Dist to and Fh Force to 0.4. Now select your character and go to the Real-timeButtons again. You have to click 'Do Fh' to enable Fh. Now play your game (clear the rotation of the top plane again before playing). Your character now hovers above the plane like it is floating on a magnetic field.

    The influence of the Fh force is linear with the distance to the object: it varies linearly from zero to Fh in the interval of Fh Dist.

    The Fh Dist value is also used for collision detection. As soon as another object enters the 'cushion', a collision is registered. What's more, the incoming object gets the color of the object that it collides with. This allows for visual debugging during playback.

    That was it for the basics of the game engine. The next step is to learn how to control your character. This is described in Controlling a Dynamic Object.