(AD-Edge) Game Stuff - Buttons


Hello all…

This is the first in what I hope is going to be a series of short tutorials all to do with the game engine in Blender 3D.:thumbsup:

In this tutorial I hope to show you how to create buttons - which when pressed with the mouse take you to another scene or some other function ect…ect

A basic understanding of Blender 3D in needed and a bit of game engine experience would be good!

Start a new scene in blender. Which version? - I’m using 2.4 but 2.37 or lower should do the job fine.
Delete the begining mesh (cube for me) and add a plane by pressing SPACE and selecting Mesh>Plane. Scale it on the X axis (‘S’ and then ‘X’) untill it is around six blocks long on the grid.
Exit edit mode (Tab)

Before we get into that we need to change the plane a bit. Select it and press ‘F’ to enter face select mode (the plane turns white). Press ‘W’ to get the specials panel up and select ‘Light’ (the plane now reacts with the light the lamp is producing and will continue to in the game engine) you can press ‘P’ to begin the game engine if you dont believe me - exit face select mode (F).

Now for the python…:eek: dont panic!!! We will only be using two lines so dont freak out!!

Change the 3D window to a ‘Text Editor’ window or just split the screen and do it in the new half (whichever is easyist).
GO File>New at the bottom of the window and you will get an area to write in (Beginners- Dont forget to breath slowly and know that you are safe… there is nothing to be afraid of)

Type the following lines:

from Rasterizer import showMouse

These lines make the mouse appear in the game window while the engine is running!
As you might have noticed it will now work yet. Go back to the 3D window and select the camera and change the panel at the bottom of the screen to the ‘Logic’ work area.
Anyone familar with Blender will know that this is where a lot of the programing for games is done.

Add a Sensor and Controller (no Actuator needed) to the Camera by pressing each of the two blue buttons. Join them together using the wires from the little bobbly objects on the sides of the newly created ‘Logic Bricks’.

Leave the ‘Always’ but change the controller to a Python :eek: (theres that scary word again) it will then ask for a script to run. You may need to go back to the text editor window to check. (mine was called Text.001) Type this name into the script window and when you run the game engine § it should work!!:thumbsup:

Now select the Plane and do the following like we did for the camera.

Add a Sensor, Controller and Actuator to the plane we just made and join them using the wires.
Change the sensor to a ‘mouse sensor’ with the drop down which would be displaying an ‘Always’ and leave the ‘Left Click’.
Add a second Sensor and change that to mouse also. Change the 'Left Click to a ‘Mouse over’ and wire it up to the Controller.
Change the Actuator from ‘Motion’ to ‘Scene’ and leave it for a second (we need to do something else first)

We have just made the main part of out button. The setup makes it so that when the ‘Mouse is over’ the object and there is a ‘Left click’ the next bit will run.

All Ok? - Lets move on then.

Add a new scene (top of the screen - Scene drop down>Add New) and quickly put anything you want in it. I filled mine up with a few cubes - it doesn’t really matter since we just need to know that the scene has changed. Make sure that there is a lamp and camera facing the new objects!!! (I hade to make new ones for the new scene)
Name it ‘New’ by pressing the name (mine was automatically called Scene.001) and go back to the first scene.

Go back to the ‘Scene’ Actuator and change its ‘restart’ to a ‘set scene’. Type ‘New’ (the name of our new scene) in the ‘SCE:’ section. remember to use capitals if you typed the name with a capital. If the name dissapears after you typed it then you havent written it exactly right

Text it and it should work!!!

If it worked :applause: nice…

If not dont get to angry :banghead: It took me a while to learn this for myself. Just be patient and go back over the tutorial when you feel like it. I suggest having a rest and going back to it another day - works for me!



This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.