The Cutting Edge Tech Blog

Blender Game Engine by Xptiger

BLENDER CAR GAME 25 February 2009

Blender (read Blender 2.48 post) is a powerful modeller rendered and game engine and was the first 3D graphics software to included a game engine and modeling software. in this tutorial you should learn the basics of making a blender game using the powerful logic brick coding system. You need to have some basic understanding of blender but none at all is needed for the game engine as all will be explained.

First of all you need to Download this basic car and track here to begin following the tutorial or you can create your own objects and models.

Step 1 – Locating the logic panel

Open up the Car game.blend file in Blender, the file should contain a car, 4 wheels a track and some cones. select the car and in the bottom panel select the icon with the pink Pac-Man in it or press  F4. this will bring up the logic editor and will allow you to start making you car move.


Step 2 – Adding Physics

there should be a menu as shown below.


Now open up the drop down menu that says static (highlighted in red) in it and select rigid body, this will allow the object to move and rotate giving it physics, and select the button that says bounds, open the drop down menu with cube in it and select convex hull (highlighted in yellow), and finally press compound. This gives the object a boundary that isn’t a sphere the size of the radius and includes anything we parent to the car the same boundary. The drop down allows you to select different boundaries e.g. cube sphere etc. Try experimenting with different bounds by selecting one and pressing p to launch the game engine.  In other words gives the car a car shape in the game. The final thing is to set the mass to 20 to give the car some weight (green). This should now look like the image below.


Step 3 – Detecting a key press

Now that we’ve given the car physics we can now move onto giving it some basic controls. We’ll start off with the forwards motion.

Under the title ‘Sensors’ press the add button this will create a new logic brick which will say always, we need to change this to keyboard. Select the drop down menu (highlighted in red) and click on the Keyboard sensor. you should see something like this.


Now Click on the button next to the word key (highlighted in yellow) and press the up key. This tells the car to do something when you press the up key. Finally change the name of the sensor to something sensible like forwards or up, this doesn’t do anything.

Step 4 – linking logic bricks

Next to the sensors there is another add button press this and another box will appear, this just allows you to have more that on controller doing the same thing.  were just going to leave it as it is unless you want to change the name. Now were going to connect them, this is really simple in blender and very intuitive. There’s a yellow dot by the sensor and a yellow ring by the controller. All you need to do is select the dot and drag it to the ring, this creates a link and means the sensor controls the controller.


This means that when you press the up key the and controller will send it to the final logic brick the actuators.

Step 5 – Movement

Now you’ve joined the Sensor to the Controller we need to make it do something. We do this by adding a final logic brick which is the actuators. So press the add button under the actuators title and join the controller to the actuators in the same way as the we joined the sensor to the controller. The final Setup should look like this or similar.


Now that we have a control we need to make it do something which is even more straight forward. In the motion actuators there are lots of zeros these are different movements you can give the car were going to be making the car go forwards, so we need to select the first column (the one highlighted in red) and type into it 200.00. The selected L’s to the right of the box are to give the car local coordinates, this basically means that the car will move depending on its rotation not relative to the world around it. Now that you have done this you can test that it works by pressing the p key again and holding down forwards. You should see the car move forwards and when you let go the up arrow it comes to a gradual stop. If you wanted it to stop instantly you could use the Loc controls (highlighted in yellow), but only set to 0.10.


Step 6 – reversing

This step if you haven’t already guessed is the same as going forwards. you need to make the same sensor, controllers and actuators but change the actuators to -200.00 instead of 10.00 and the sensor key to a down arrow. Now if you test the car can go forwards and backwards.

Step 7 – cornering

First of all create a sensor, controller and actuators and make the same type as the ones for going forwards and backwards then in the Sensors box make the key a right arrow. After, in the actuators box make the third box in the Rot row have a value of -0.10. This makes the car turn. There’s only one problem with the system for cornering in blender and that is, that you can turn when you not moving and the only way to get round that is using python but were not going to go into that. So the box should look like this.


Now to turn left just do the same but change the Rot box to 0.10.

Step 8 – Attaching the wheels.

Select the four wheels that are underneath the car and then the car, you must do this in this order or it won’t work, and press ‘command’ if you on a mac or ‘control P’ for a PC. this means that if you drag the car around the screen the wheels are now attached.

[EDIT:] You will then need to select each wheel individually and press  bounds, then  select Convex Hull in the drop down and finally press Add To Parent as shown below. This will stop the car wildly flying off which a lot of people have been experiencing (sorry for not including this originally).

Step 9 – Making the wheels turn Right

To save time the wheels already have IPOs linked to them so you can just give them controls to turn them. First select one of the front wheels and go onto the logic editor if your not already on it. Select the drop down that says static and change it to dynamic and the give it a bound thats a convex hull. Now add a new sensor, controller and actuators and join them up. After change the sensor to keyboard and change the key to a right key and change the actuators to a IPO type. all this means is that the IPO will play when you press the right arrow. we then need to change the second number (highlighted in red) to 5 and Change the drop down (highlighted in yellow) to a Flipper type. This means that the IPO will play from frame 1 to five and because the Flipper type is selected it will go back to 1 again.


Step 10 – Making the wheels turn left

Making the wheel turn left is the same as making it turn right except the IPO start and begin numbers need to be different. First make a new set Controls with the left key not the right key in the Sensor. you can the change the IPO end number to 10 and the Start number (highlighted in red) to 6. This makes the IPO Begin at 6 not 1 so it doesn’t got right then left!


Now repeat for the other wheel front wheel.

The car is now complete unless you want to add some crazy feature like making it jump straight up.

Step 11 – Making cones to crash into.

all we are doing for this section is creating a cone that is movable but reacts to environmental changes not programmed movements. So select the cone and change the static drop down menu to ridged body. Then give it a bounds of convex hull and your done. You can now duplicate the cone as many times as you want using the shortcut key ‘Shift D’.

Step 12 – Completion

You have now successfully completed the car game. If you have any quires please leave a message. if you want to take this game further there’s a very useful tutorial here which explains in detail how to give the car suspension and decent steering using python. I’ve personally used it and completed my first game which will be available to download when I get round to giving it the finishing touches.

Add to Technorati Favorites Paypal


26 Comments so far
Leave a comment

How can I do it?

Comment by Taha

That’s a good post. You can see the result of implementing BGE as the engine for racing game.
The game is free and open – you could look inside to see all the technique and scripts. You could use anything you want of it.

Comment by skidrules

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: