From BlenderWiki

Jump to: navigation, search
Image:LeftArrowHeader.png
[[{{{2}}}|      ]]>
Image:RightArrowHeader.png
[[{{{3}}}|      ]]>
Blender Summer of Documentation: Contents | Manual | Blender Version 2.42

[edit] Making the default cube move, using no physics

We will initially use direct manipulation to move the cube within the scene. Later on, we will set up a similar scene, but will use physics to move the cube around the environment. By using the built-in physics engine (called Bullet), more complex scene interactions such as collisions and gravity will be handled automatically.

Have a look at the Motion actuator, especially the 3 numerical boxes beside the dLoc label. Each of the 3 boxes in this dLoc area can be used to specify a change to the location of the object along the X, Y or Z axis specifically.

Keeping Track Of Directions

To keep track of what direction X, Y and Z are in, keep an eye on the visual axis in the bottom left of the 3D view. Image:BSoD-Introduction_to_the_Game_Engine-OnScreen_Axis.gif

Image:BSoD-Introduction_to_the_Game_Engine-Motion_Actuator_Initial.gif

Change the middle dLoc numeric value (Y axis, or forward) to be 0.1.

Image:BSoD-Introduction_to_the_Game_Engine-Motion_Actuator_Change_Dloc_Y.gif

Now press P. You will notice that the cube continually moves along the Y axis. Press Esc to return to Blender.

Press P again and you will notice that the exact same sequence of events in the GE occurs again. Press Esc to return to Blender again.

To recap on what is happening in the GE - the timer (Sensor) sends out a signal every frame to the Cube's Controller. This then sends the signal through to the Cube's Actuator, which will then call the Motion object, which moves the cube object 0.1 units in the Y axis. As it is called every single frame, it looks like the cube is continually moving. If you let this game run, the cube will eventually glide off to infinity. This is about as fun as watching grass grow, so read on!

[edit] Controlling the cube via the arrow keys

In the example above, the timer is responsible for moving the cube forward. We will change this now, so that it is controlled using a keyboard press.

On the Always sensor, click on the <> beside the Always label. This will bring up a list of the available sensor types.

Select Keyboard from the list. The Sensor will now change to show the Keyboard options.

This new sensor panel will allow us to choose a key that needs to be pressed before a signal is sent to the controller, which in turn will pass it on to the actuator.

Click on the button area beside the Key label, and when it changes to say press a key, press the key.

Press P to play the game again. The cube will not automatically move now. Press the key, and it will start to move forwards. When you stop pressing the key, the cube will stop moving. Press again to move the cube again. Press Esc to return to Blender.

[edit] Adding in additional keyboard controls

We will now add in the ability to move the cube backwards, as well as rotating it, to allow you to move it around the 3D environment.

To add the ability to move backwards, we will add in a new (but nearly identical) set of GE logic bricks. Click the Add button again on the Sensor, Controller and Actuator areas, to create 3 new logic bricks on the GE panel. Connect these up as before.

NOTE - You might want to use the Ctrl key to maximise and restore the game logic panel when working in it, as it will become cluttered very quickly.

With the newly added sensor, change it to keyboard type, and set it to use the arrow key. In the newly added Motion actuator, change the Y value (2. column) of the dLoc area to be -0.1.

Press P to play the game. If the logic blocks are set up correctly, you should now be able to move the cube forward and backward just by using the and arrow keys.


To complete this "no physics" part of the tutorial, we will add in the ability to rotate the object as well, so that you will be able to "drive" your model around the 3D environment.

Add in 3 new logic blocks as before, connect them up, and change the sensor type to keyboard. Set the keyboard entry to use the arrow key.

Now, in the Motion Actuator, we will set it up to rotate the cube. To do this, we will rotate the object around its Z axis. In the dRot area, change the 3rd number (Z) to be -0.1.

Press P to play the game. When you click the key, the cube will rotate. When you press the arrow key, the cube will move forward in that direction. Press Esc to return to Blender, and we will add in the ability to rotate the other way.

As before, add in 3 new logic blocks as before, connect them up, and change the sensor type to keyboard.

Set the keyboard entry to use the arrow key, and the Z value (3. column) in the dRot section in the Motion actuator to be 0.1.

Press P again to run the game. You can now "drive" the cube around the 3D environment using the arrow keys. Note 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. Press Esc to return to Blender.

[edit] Some GE house keeping

We will now name some of the sensors and minimise them, to keep the game panel as uncluttered and readable as possible. This won't affect what the actual logic does, but it will help keep the game logic area more manageable.

Press Ctrl in the game panel to make it full-screen.

In the first sensor panel, beside where it says Keyboard, you will see an area where the text Sensor appears. This can be changed to something more descriptive. Change this text to "up key". Also, press the arrow button beside this to minimise the Sensor panel.

Repeat this for the other keys. Also, do the same in the Actuators, giving them a descriptive title (for example move forward, turn left, etc...).

Press Ctrl again to restore the game panel to its original size.

As you can see, having the various blocks named make it a lot easier to figure out what is going on.

[edit] Removing logic blocks and connections

Remove a logic block.

To remove logic blocks, press the X button at the top left corner of the logic blocks.

To remove the connections between logic blocks, move the mouse over the line connecting the blocks and press the Del key.

--Mal_CanDo 17:00, 18 August 2006 (GMT)








Redirects to fix

  • BSoD/Introduction to the Game Engine/Moving the cube using physics → Doc:Tutorials/Game Engine/BSoD/Moving the cube using physics
  • BSoD/Introduction to the Game Engine/The basics of the Blender GE → Doc:Tutorials/Game Engine/BSoD/Basics of the GE
  • Blender Summer of Documentation → BSoD
  • Manual/Manual → Manual