hello BA
i was working on a player movement script to navigate , without any logic bricks but it only works when i press the buttons multiple times and not holding
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
speed = 0.2
keyboard = bge.logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
if JUST_ACTIVATED in keyboard.inputs[bge.events.WKEY].queue:
own.localPosition.y += speed
if JUST_ACTIVATED in keyboard.inputs[bge.events.SKEY].queue:
own.localPosition.y -= speed
if JUST_ACTIVATED in keyboard.inputs[bge.events.DKEY].queue:
own.localPosition.x += speed
if JUST_ACTIVATED in keyboard.inputs[bge.events.AKEY].queue:
own.localPosition.x -= speed
Thanks for the help guys , i tried changing " KX_INPUT_JUST_ACTIVATED " to " KX_INPUT_ACTIVE " and it do nothing , then i copied your script and it still idle , with no bugs showed in the console , what i am doing wrong ?
Srry. I’m a bit tired this week and for some reason my brain though “BGE” instead of “UPBGE”, which is weird, since I saw the keyboard.inputs which is only for UPBGE…
For UPBGE instead of doing == 2 you do .active.
Script
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
speed = 0.2
keyboard = bge.logic.keyboard
if keyboard.inputs[bge.events.WKEY].active:
own.applyMovement([0,speed,0],1)
if keyboard.inputs[bge.events.SKEY].active:
own.applyMovement([0,-speed,0],1)
if keyboard.inputs[bge.events.DKEY].active:
own.applyMovement([speed,0,0],1)
if keyboard.inputs[bge.events.AKEY].active:
own.applyMovement([-speed,0,0],1)
I also replaced the localPosition transform with applyMovement(), since it’s easier to use.
for an non-parented object, localPosition and worldPosition are basically the same thing.
also id advise to actually type out True where a boolean is expected, otherwise its confusing to those not fluent in the api. (yes, 0 is false and 1 is true, i know.)