Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
    
You don't use bpy in the game engine.. –  iKlsR Jul 8 '13 at 15:53

1 Answer 1

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

share|improve this answer
    
+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. –  Blue Aug 16 '13 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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