actuators don't deactivate

Hy,

was just starting out with a basic script for movement. But somehow the code given here doesn’t exactly work.
I’m using the second example. But the actuators don’t get deactivated (and manually deactivating them doesn’t make it better). Here is my setup:


And another question: Is it possible to detect multiple key presses? Like when you want to run diagonally when pressing left and forward at the same time?

if condition_1 is true and condition_2:
do stuff

Please enlighten me, because I don’t really understand what your are trying to say.

If you activate a actuator with python it will continue activated until you deactivate it, deactivate it with: controller.deactivate(“actuator name”), and I think the method you are using for move the player is not so good.

Exactly the title is the solution: If you activate the actuator you need to deactivate it as well.

I thought so. But then the example given on the api page is pretty much useless.
Anyway, the script I now have looks lik this:


import bge




cont = bge.logic.getCurrentController()
keySensor = cont.sensors["Keyboard"]


cont.deactivate(cont.actuators["forward"])
cont.deactivate(cont.actuators["left"])
cont.deactivate(cont.actuators["right"])
cont.deactivate(cont.actuators["backward"])


for key,status in keySensor.events:    
    if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
        if key == bge.events.ZKEY:
            cont.activate(cont.actuators["forward"])
        if key == bge.events.QKEY:
            cont.activate(cont.actuators["left"])
        if key == bge.events.DKEY:
            cont.activate(cont.actuators["right"])
        if key == bge.events.SKEY:
            cont.activate(cont.actuators["backward"])
            

And it is better, but it doesn’t give a smooth movement experience. When quickly changing between directions, movement sometimes completely stops. Any suggestions?

The movement depends on the motion actuator, if you want smoother motion try the servo control movement instead of simple.
In regards to using the ‘and’ statement BPR was talking about, I would think that this means not only checking whether the key has been pressed but also checking whether the KX input has been activated

So ‘if status == bge.logic.KX… and bge.events.ZKEY:
do stuff’

Therefore this would only work if both criteria had been met.
Eitherway if deactivating the actuator is working for you then just use that option.