Movement on one axis with python


Is it possible to just set the movement in one axis, instead of having to type 0 at the ones that I don’t really need. I have tried several things, but can’t get it working.

import bge
from bge import logic,events

cont = logic.getCurrentController()

motion = cont.actuators["Motion"]

if[events.UPARROWKEY] == logic.KX_INPUT_ACTIVE:
    motion.dLoc = [0, 0.1, 0] #Set this one to be on only one axis instead of typing all three values.
    motion.dLoc = [0,0,0]

Is it a real problem to have to type those extra zeros? Because at the same time you tell in the code, and make sure, that those two unwanted axis are eliminated out of the movement making sure it’ll move only along the wanted axis.

But if for example the user presses a button and the speed will increase in one direction you cannot set the others to be zero.

If You have different keys for moving in different directions connect all key sensors to the same python controller and set movement in all directions in one call.

If You must have different scripts for some reason get the speed first and set the axis You don’t want to change to the same value they already have.