1
$\begingroup$

I'm pretty new to the bge, which I'm using for a school project and right now I'm having a problem with my movements.py script. I know this question is quite 'noobish' but I just can't find the problem. The 'player' object is just a cube with character physics and actor enabled but won't move when I start the game simulation and press the different keys.

import bge


def main():

    cont = bge.logic.getCurrentController()
    player = cont.owner

    keyboard = bge.logic.keyboard

    if keyboard.events[bge.events.WKEY] == bge.logic.KX_INPUT_ACTIVE:
        player.applyMovement((0, .2, 0), True)    

    if keyboard.events[bge.events.SKEY] == bge.logic.KX_INPUT_ACTIVE:
        player.applyMovement((0,-.2, 0), True)  

    if keyboard.events[bge.events.AKEY] == bge.logic.KX_INPUT_ACTIVE:
        player.applyMovement((-.2, 0, 0), True)

    if keyboard.events[bge.events.DKEY] == bge.logic.KX_INPUT_ACTIVE:
        player.applyMovement((.2, 0, 0), True)

main()
$\endgroup$
4
  • $\begingroup$ Can you elaborate on what your problem is? "I'm having a problem with my script" does not really tell us anything. $\endgroup$
    – David
    Commented Mar 18, 2017 at 23:36
  • $\begingroup$ Yeah, sorry for that. Edited the question. My character won't move like he should with this script. Nothing happens at all. $\endgroup$ Commented Mar 19, 2017 at 0:16
  • $\begingroup$ I made a quick scene using your script and the cube move fine. Make sure the Sensor running your script is always running. i.sstatic.net/Uv0Cr.png Connect an Always sensor to the Python controller and activate TRUE level triggering. $\endgroup$
    – David
    Commented Mar 19, 2017 at 0:47
  • $\begingroup$ Thanks, forgot about this one. Used BGE like 5 years ago so I couldn't remember small things like this. $\endgroup$ Commented Mar 19, 2017 at 9:48

1 Answer 1

1
$\begingroup$

TLDR: You need to enable True Level Triggering.

By default the "Always" Sensor only runs once, when game starts.

Any time you need something "always" triggered then you must click the little button with the three dots on the right side of the "Always" Sensor called "True Level Triggering" (I have it marked in red in the image below).
Always sensor and Python controller

So your script works fine, just it was not running during the game.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .