Hey,
Yesterday I started learning python. cthames and vibrunazo helped me to make the following script for movement:
get the current controller
cont = GameLogic.getCurrentController()
get owner
own = cont.getOwner()
import GameKeys Module
import GameKeys
get sensor named key
keys = cont.getSensor(“key”)
get actuator named motion
motion = cont.getActuator(“motion”)
set variables
speed = 0.1
rspeed = 0.02
walk = 0.0
turn = 0.0get Game key code for W key
wKey = GameKeys.WKEY
sKey = GameKeys.SKEY
aKey = GameKeys.AKEY
dKey = GameKeys.DKEYif get key status is 1 (just pressed)
if keys.getKeyStatus(wKey) == 1:
walk = speed
if keys.getKeyStatus(sKey) == 1:
walk = -speed
if keys.getKeyStatus(aKey) == 1:
turn = rspeed
if keys.getKeyStatus(dKey) == 1:
turn = -rspeedmove on local y axis
motion.setDLoc(0, walk, 0, True)
rotate on world z axis
motion.setDRot(0, 0, turn, False)
use actuator
GameLogic.addActiveActuator(motion, True)
The problem is that I can’t press 2 keys at a same time, to move forward and rotate at the same time. How can I make this?
Thank you =]