EDIT (question is still valid though) I discovered that the issue was not the code, it was the object. I had Character physics on my cube, and it needed to be Dynamic.
Still, I would like to know how to fix the issue, since I prefer Character physics.
So I'm going through a basic tutorial in which I need to apply forward momentum to a cube. Here's my Python script.
import bge def main(): cont = bge.logic.getCurrentController() player = cont.owner # KEY EVENTS key = bge.logic.keyboard activekey = bge.logic.KX_INPUT_ACTIVE releasedkey = bge.logic.KX_INPUT_JUST_RELEASED _w = key.events[bge.events.WKEY] _a = key.events[bge.events.AKEY] _s = key.events[bge.events.SKEY] _d = key.events[bge.events.DKEY] _shft = key.events[bge.events.LEFTSHIFTKEY] w = activekey == _w a = activekey == _a s = activekey == _s d = activekey == _d shft = activekey == _shft wrel = releasedkey == _w arel = releasedkey == _a srel = releasedkey == _s drel = releasedkey == _d spd = .1 mmt = 100 if shft: spd = spd*2 if w: player.applyMovement((0, spd, 0), True) if wrel: player.applyForce((10000,0,0), True) if s: player.applyMovement((0, -spd, 0), True) if a: player.applyMovement((-spd, 0, 0), True) if d: player.applyMovement((spd, 0, 0), True) main()
I'm focusing on this line:
if wrel: player.applyForce((10000, 0, 0), True)
Whenever I play this, my cube moves, but then stops instantly. I tested the wrel variable to make sure it worked by:
A. using a print function and checking the command line (successful)
B. using an applyMovement function (successful)
But when I change applyMovement to applyForce, it yields nothing.
What am I doing wrong?