Introduction

What we want to achieve here is to create our own mini test engine for our track, in the simplest but most effective way as possible. No programming skills are required either, we are going to use a feature in Blender’s Game Engine called ‘Logic Bricks’ - I will explain more about those later in the tutorial.

Adding The Required Objects

To start, we need to add the two elements that are needed for this to work; the camera and an ‘empty’ object. Switch to the opposite side view (’Ctrl+Numpad 3′), then orthographic mode (’Numpad 5′) and place the 3D cursor to the side of the track. You then need to add an ‘empty’ object, so, press ‘SPACE > Add > Empty’ then ‘Alt+R’ to clear/reset the rotation. You can always zoom in if the object is too small to see. This ‘empty’ will be used as the controller for movement and physics.

For the camera - press ‘SPACE > Add > Camera’ and again clear the rotation (’Alt+R’). Then rotate it along the ‘X’ axis, preferably so it’s tilted slightly downwards to the right. Finally, move it upwards about 1/3 of the way along the ‘Z’ axis. Your objects should now be in the following arrangement:

Camera and empty in correct arrangement.

What we need to do now is ‘attach’ or ‘parent’ both of these objects to each other. Make sure you have the camera selected first (this is important) and then select the ‘empty’ and press ‘Ctrl+P’ (’OK? - Make parent’). Both the objects should now attached in the correct manner.

Enabling Physics

Of course these objects won’t do anything unless we apply some physics. Select the ‘empty’ and in the buttons window switch to ‘Logic’ (F4). This is where we will be applying all the dynamic stuff for our engine.

For now, select the ‘Actor’ button in the top right and then ‘Dynamic’. You should see a range of settings appear. Change them to the following values:

'Empty' physics settings.

These values are, from experience, the best to use for what we are trying to achieve. The ‘Mass’ affects the acceleration speed of an object, the ‘Size’ is the size of the collision bounds of the object, the ‘Damp’ or ‘Dampening’ acts against movement (like air resistance), and the ‘RotDamp’ or ‘Rotational Dampening’ affects the rotational speed.

You’re probably pretty eager to find out what these settings have done. Unfortunately it won’t do too much at the minute, but it’s best to check everything is working as it should. Select the empty object and move it fairly high above the track (the camera will follow), then set that camera as the default (select it then press ‘Ctrl + Numpad 0). Now press ‘P’. You should see your camera fall and stick to the the ground. If it does that then that means everything is working, if not then I would either check your physics settings or check the parenting.

Material & Camera Settings

I think you’ll agree - it’s not overly exiting when it just ’sticks’ to the ground like that; I prefer to have no friction just for the fun of it, so you can slide down the sloped areas easily. To do this, we need to change the track’s material settings.

Select the track and switch to the materials or ‘Shading’ buttons (’F5′). Within this, enable the ‘DYN’ button to reveal a few extra settings for physics. For the result we are trying to achieve, we want it to be slightly bouncy and very slippery, so, set the friction to ‘0′ and the ‘Restitut’ to ‘0.3′:

Material 'DYN' physics settings.

Now play the game (’P'). You should notice your camera fall, bounce a little, then slide down the track. We’re getting there…

Depending on the scale of your track or skydome, you will probably notice a restriction to how far the 3D is displayed. This is because of camera ‘clipping’. For the engine to run faster the game engine clips off a certain distance from the camera, which doesn’t look too good. To fix this, simply switch to the ‘Editing’ buttons (’F9′) and change the ‘End’ value to something like ‘1000′ to be safe, but again this depends upon the scale of your track. This will push the clipping distance further away so that the view is extended.

Camera settings.

Adding Control

Now for the most exciting part of this tutorial - adding interactive functionality. The process is actually easier than you think, especially with Blender’s Game Engine. In this situation we will be using a system called ‘Logic Bricks’; These allow you to apply simple actions and functionality quickly and easily without the need of any programming.

To get started, switch back to the Logic buttons window (’F4′). If you take a look to the right of the physics properties, you will see three columns of buttons - this is what we will be using. These are, in order: ‘Sensors’, ‘Controllers’ and ‘Actuators’.

We are going to be applying the functionality to our ‘empty’ object as mentioned earlier, so, select it and then where it says ‘Add’, click this button under all of the three columns. It should now look like this:

Logic bricks.

First of all we will add a forward thrust to our object which will trigger when we press a button on the keyboard, I will be using the ‘up’ arrow. In the sensors column, bring down the menu list where it says ‘Always’ and select ‘Keyboard’. To specify the button which you wish to use, press the grey bar to the left of where it says ‘Key’ and press the desired key. You should end up with this:

Keyboard settings box.

In this case we don’t need to worry about the next column, so just leave that as it is for now. Moving onto the third and final column, fortunately it’s at the settings that we need to use, this is where we specify the forces or movement which is applied to our object. We will be using ‘Force’, and the different value boxes are in the order of X, Y and Z. We have the camera facing along the Y axis, so we need to change the middle box. Set the value to around 0.2, this should be about the right setting to use, not too fast and not too slow.

In order to get these to work we need to join them up, so if you think about the columns logically, it should process as ‘Keyboard’ ‘AND’ ‘Motion’ - so when you press the button you specified, it applies the motion. What you need to do is drag your mouse from the gold ball points to the gold holes and a line should automatically snap to each brick. Like so:

Logic bricks joined and completed.

If you need to remove an attachment, hover over the line you wish to remove and press ‘X’. You can now test to see if it all works. If you press and hold the button you specified in the bricks you should see your camera thrust forward. Obviously you can always adjust the speed in which it does this in the motion box.

To finish off with keyboard control, add three more logic bricks to each column (for the down, left and right keys) and join them all up. With the down arrow, it’s pretty much the same as the up but with a negative thrust value e.g. ‘-0.2′.

For left and right movement we need to rotate the camera, again, the same procedures as with the up arrow, but this time instead of entering the values in the ‘Force’ row we need to enter values in the ‘Torque’ row. Torque is force rotation, it’s a bit like a spinning top, you apply the spinning force in order for it to turn and gradually the turning momentum decreases. So, again the same principles but this time you need to remember that you are turning along the ‘Z’ axis which means you need to enter your values in the last column. A positive for left turning and a value negative value for right turning, both ‘0.003′.

Now, if you test it, you will be able to move forward, backwards and turn left and right. The logic bricks should look something like this:

Final logic bricks setup

There are also three other bricks I like to add; a fly button, a camera button and a scene reset button. Before you do that, you might like to collapse the current bricks so you have more room, all you need to do is press the small orange down arrow button on the top right of each of them. Once you’ve done that, again, add three more logic bricks to each column and join them up. The first still only need to be set as keyboard sensors, and the second still remains as ‘AND’. The bricks we will be changing are the ‘actuators’.

If we choose the order of ‘flying’, ‘camera’ and ’scene resetting’ you can define the keys to be pressed to trigger these events. I will be using ‘Ctrl’, ‘1′ and ‘R’. Now take a look at the actuators, the first we will be modifying is the flying. All you need to do is think about force and ‘Z’ thrusting, so leave it as ‘Motion’ and apply a value of ‘0.3′ to the top right field. If you test it out, you will see that if you press the key you specified, you can fly around your track.

The next we move onto is the camera. For example, if you can’t be bothered to switch to that camera every time you want to test it out, when you play it, press the button you assigned and it will automatically change to that camera. Press the drop-down list where it says ‘Motion’ and select ‘Scene’, another drop-down list will display. Press it, and select ‘Set Camera’. What you need to do now is assign a name to your camera e.g. ‘cam1′. To do that, select the camera, switch to the ‘Editing’ settings and then enter a name into the field where it says ‘OB:’, remember it is also case sensitive. Switch back to your ‘empty’ and enter that name into again, where it says ‘OB:’. If you test it now, you will see that the button you specified will automatically switch to that camera.

Last but not least, for the scene resetting, all you need to do is bring down the list again where it says ‘Motion’ and select scene. It is already set to ‘reset’ so it should work ok. Again, test it out, you can use this for example if you fall off the track. Here’s a final screen of what your logic bricks should look like:

Extra logic bricks.

Final Conclusion

Phew, after all of that I think you deserve a cup of tea and a sit down; well, so do I in fact. Despite the length, I hope you have enjoyed this tutorial in a way and gained something from it. If you have then that’s fantastic. At the same time I’d also love to hear your feedback on what you thought - did you enjoy it? How difficult did you find it? How could it be improved? Better still I would be very interested to see your end result (maybe some screenshots?), and possibly, with your permission, I may even publish it on the website.

Tutorial Files

I’ve had many requests to include the files I used in this tutorial for download, so I’ve made them available here:

Download Files