I want My cube to move on the ‘Z’ Axis my 1 blender unit only when I press the ‘W’ Key. In the logic of the cube I have a keyboard sensor named ‘Keyboard’ connected to a python controller selecting the script i want to run. i am new to programming/scripting and i have been trying to learn BGE python for a while now
Can someone please tell me why this script is not working?
I made it, by going back a forth to different pages in the BPY python documentation
OMG i just realized i didn’t even but the script i wrote in the post lol
so this is the first script i ran
import bge
#class Player(bge.types.KX_GameObject):
cont = bge.logic.getCurrentController()
sensor = cont.sensors[“Keyboard”]
obj = cont.owner
for key,status in sensor.events:
if status == bge.logic.KX_INPUT_JUST_ACTIVATED: if key == bge.events.WKEY: obj.localLinearVelocity.y += 20 print("Key Pressed")
then this is the second script i ran
import bge
import mathutils
cont = bge.logic.getCurrentController()
obj = cont.owner
sensor = cont.sensors[‘Keyboard’]
key = sensor.events
if key == WKEY:
obj.worldPosition.z += 1