Graphics Reference
In-Depth Information
The activate() method needs to be called again to activate the Motion activator with the correct para-
meters for making the character move. Once again, dir() will tell you what the possible properties are that
can be set on a Motion actuator. In this case, you use dLoc and dRot to set the location and rotation speed.
The order of the arguments represents the order of the fields on the Motion actuator logic brick. The code for
setting these parameters and adding the active animator is as follows:
motion.dLoc = [0,0,walk]
motion.dRot = [0,turn,0]
cont.activate(motion)
And with that, the movement controls for the character are finished. Run your game by pressing P and test it
out. Be sure to have your console open as described in Chapter 12, “The Blender-Python Interpreter,” to watch
for errors or warnings from Python.
Python Power for the BGE
Now that you know the basics of how to control a character with Python, you should be on track to understand-
inghowtomimicmuchofthecorefunctionalityoflogicbrickswithPython.TheAPIandthe dir() command
will be your friends as you explore this further. This section describes various ways you can use Python to get
effects that are difficult or impossible to achieve with only logic bricks.
Creating a Teleportation Machine with Python
Using Python, it is simple to place an object anywhere in the 3D space. The next example shows you how
to “teleport” objects from one place to another when a sensor is triggered. The setup here is as shown
in Figure 16-2 , and you can find the .blend files on the website for this topic. The completed file is
called portals.blend , and the starting file with no logic, physics, or script attached is called
portals_nologic.blend .
 
Search WWH ::




Custom Search