0
$\begingroup$

I have a script that allows a cube to be moved using WASD. I'd like to avoid having to use actual keyboard input for that and thought about creating a separate file with commands like "Wkey" and such. I'd then have a function read through the file and have the agent respond to the commands in the file accordingly. Is this possible/if so, how would I go about doing it? (New to blender/still relatively new to python honestly)

Script below:

import bge


def main():

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

    keyboard = bge.logic.keyboard

    wKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.WKEY]
    sKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.SKEY]
    aKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.AKEY]
    dKey = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DKEY]

    if wKey: 
        own.applyMovement([0,0.2,0],True)

    if sKey: 
        own.applyMovement([0,-0.2,0],True)

    if aKey: 
        own.applyMovement([-0.2,0,0],True)

    if dKey: 
        own.applyMovement([0.2,0,0],True)

main()
$\endgroup$
  • $\begingroup$ I've been thinking about this-since wKey, sKey, aKey and dKey are all bools, can I just start off (in the same file) setting them to true? I tried wKey = 1 and stuff and vaguely remember a .ispressed() function but can't remember the proper syntax... $\endgroup$ – Archana Ram Jul 31 '15 at 0:39
  • $\begingroup$ yeah, sorry-i should delete that one...this is more in line with what i want to do $\endgroup$ – Archana Ram Jul 31 '15 at 4:17
  • $\begingroup$ I'm not sure, but you might edit the first question to fit your needs. $\endgroup$ – Monster Jul 31 '15 at 4:45