Blender 3D: Noob to Pro/Platformer: Creation and Controls< Blender 3D: Noob to Pro
|Applicable Blender version: 2.49.|
This tutorial will teach you the basics of the Blender Game Engine, and how to create a platform game, which is a game where you overcome in-game obstacles by controlling the character's motions. (e.g. Super Mario)
To start, switch to the frontal view NUM1 and move the starting cube to -3.0 along the Z azis, or three spaces down. If your default settings do not have you starting with a cube, create one now. (Don't forget to switch to the Blender Game engine. You can do this by going to the button on the top center of the screen that says Blender Render and switch it to Blender Game.) Next, hit SPACE → Add → Mesh → Monkey to create Suzanne the Monkey. Any mesh will do, but it's the easiest of the basic meshes to intuitively determine local direction from. Next, go to the logic window (with Suzanne still selected) and toggle on "Actor" and then "Dynamic". Hit PKEY to test. Suzanne should fall, then stop upon hitting the cube. Press ESC to exit.
Now we will add the controls. First, forward:
In Blender 2.59 these controls are available in the 'Logic Editor' window.
- Create a Keyboard Sensor, AND Controller, and Motion Actuator. Connect them by dragging lines between the dots next to their names. (In 2.59 the controller is created automatically, if the other two are connected)
- Select the empty box next to the word "Key" on the Keyboard Sensor and hit the up arrow key on your keyboard.
- Set the dLoc on the Motion Actuator to 0.10 Z and toggle Local Transformation (may appear as simply an L next to the dLoc row).
Next, backward. Repeat the process used for forward, but set the dLoc to -0.10 Z and the key to the down arrow. You can repeat this for left and right if you so choose to have a linear control scheme. We will not be using such a scheme for this tutorial, but you should still be able to follow along just fine. Instead, the character will rotate left and right and move in the new forward and backward.
To rotate right:
- As before, create a Keyboard Sensor, AND Controller, and Motion Actuator, then connect them.
- Set the key to the right arrow and set the dRot to -0.10 Y.
Repeat for left, with the left arrow and 0.10 Y.
Finally, the ubiquitous, and some say defining, Platformer move: the jump. Repeat the previous processes, with the space key as the trigger and the linV of the motion effect as 7.50 Z (not local). This doesn't actually move the character in a certain direction, but sets its velocity. If you've done programming for games before, this will probably be familiar to you. Each frame, the engine adds the velocity of the object to its current position. The gravity portion of the engine subtracts from the upward velocity each time. When it reaches a negative, it's adding a negative number to its altitude, ergo subtracting from it, ergo causing it to fall. This is why using linV to move the character does not cause it to immediately relocate to the target position.