Having a bit of an issue making a player movement script. I am handling everything in python and not really using any logic bricks except for the keyboard(all keys) and another that detects if on ground. I have looked pretty hard on google for something that would help. No luck for me. Maybe I am just searchin for the wrong thing, lol.
The Problem
Right now the code works for each direction. forward back left right. Jump is a bit buggy at the moment. If anyone can fix it that would be great or if you have a good jump script that I can incorporate that would be awesome as well. There is one issue that it has. If you press two directions at once, and exact at the same time, it works, but if you press one direction then press another direction it moves along the new directions setting. Example below:
Press WKEY to move forward, then press AKEY to more forward and turn left results in just turning left. Forward speed stops. I have a feeling it has something to do with the dLoc and dRot but I am not sure. If you need more information let me know.
import GameLogic
import GameKeys
#import Rasterizer
move_forward = GameKeys.WKEY
move_backward = GameKeys.SKEY
move_turnleft = GameKeys.AKEY
move_turnright = GameKeys.DKEY
action_jump = GameKeys.LEFTSHIFTKEY
cont = GameLogic.getCurrentController()
own = cont.owner
pos=[0,0,0]
rot=[0,0,0]
force=[0,0,0]
def movement():
Speed = 0.2
Turn = 0.05
Jump = 1
#Run = 0.35
keyboard = cont.sensors['keyboard']
onGround = cont.sensors['onGround']
move = cont.actuators['movement']
keylist = keyboard.events
for key in keylist:
print str(str(key[0]) + ":" + str(key[1]))
print str("")
if key[1] == GameLogic.KX_INPUT_JUST_ACTIVATED:
if key[0] == move_forward: pos[0] = Speed
if key[0] == move_backward: pos[0] = -Speed
if key[0] == move_turnleft: rot[2] = Turn
if key[0] == move_turnright: rot[2] = -Turn
if key[0] == action_jump:
if onGround: force[2] = Jump
move.dLoc = pos
move.dRot = rot
move.force = force
cont.activate(move)
movement()