Graphics Programs Reference
In-Depth Information
These six sensors will be the ones detecing when the user presses any of the keys
used for the horizontal movement (WASD) or scrolls the mouse wheel (to move
verically).
9. Now let's go to the controllers column and add a new controller of type
Python
Script
. For this controller, we only set its name for now; let's call it
move
. Remember
the name of the controller (upper part of the logic brick) itself is disinct from the
text datablock that will contain the actual code (lower part of the controller logic
brick).
10. Finally, let's add an actuator (third column) of type
Motion
and change its name to
baseMover
. Let's also connect the output socket of each one of the six sensors of
the base object to the input socket of the
move
controller, and connect the output
socket of the
move
controller to the input socket of the
baseMover
actuator.
Apart from the logic bricks, we also need to add
properties
to the base object.
11. Let's put the mouse pointer inside the Logic Editor and press the
N
key to show the
sidebar; then click on the
Add Game Property
buton twice. The irst property must
be named
walkSpeed
, its type set to
Float
and its value set to
0.1
. The second
property must be named
flySpeed
, its type set to
Float
, and its value set to
2.0
.
Properies are just a way to give an object the responsibility to hold some data that
we can use in the logic. In this case, this object is the one that knows how fast to
walk
(horizontal movement) and how fast to
fly
(verical movement).
12. Now let's select the derived object in the 3D View and only add an actuator to
it in the Logic Editor; the actuator must be of type
Motion
and its name must
be set as
viewRot
.
13. Finally, let's select the
mainControl
object, then go to the Logic Editor and add
three sensors as follows:
F
Sensor 1:
Type: Mouse
Name: click
Mouse Event: Let Buton
F
Sensor 2:
Type: Mouse
Name: unclick
Invert: Enabled
Mouse Event: Let Buton