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?

https://i.sstatic.net/WpmUm.png

\$\endgroup\$
1
  • \$\begingroup\$ You don't use bpy in the game engine.. \$\endgroup\$ Commented Jul 8, 2013 at 15:53

1 Answer 1

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\$ Commented Aug 16, 2013 at 11:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.