2
\$\begingroup\$

I'm trying to learn how to use BGE, and one of the things I'd like to do is programatically move the cube using a python script. I added a controller but no luck. See screenshot. I'm trying to run the python script at the top of the page, all it's supposed to do is move the cube a little. It works if I click "Run Script" but I want it to happen automatically when BGE is running. What am I missing?

http://i.imgur.com/7KsoiAd.png

\$\endgroup\$
1
  • \$\begingroup\$ You don't use bpy in the game engine.. \$\endgroup\$ – iKlsR Jul 8 '13 at 15:53
1
\$\begingroup\$

As well as using bge (the blender game engine module) instead of bpy, you want to set the true or false level triggering to get the always sensor to repeatedly call the python script. That is the buttons to the side of the Freq setting which will determine how often it will be triggered.

import bge
bge.logic.getCurrentController().owner.localPosition.z += 0.01

would be the replacement code for what you have. You may find that this will be better joined with a keyboard sensor to move the object when you press a key.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ +1 Tested and confirmed, a good answer - expanding it with a little more detail may help people finding this answer later on better understand how this worked. \$\endgroup\$ – Tom 'Blue' Piddock Aug 16 '13 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.