Basic Movement - Using 2 sensors to move a direction

Hello, I’ve browsed the forums and I can’t seem to find a fix for this. I’m new to python and built on a previously made script. I’m trying to use two sensors at the same time, but I don’t know how to implement it.


cont = bge.logic.getCurrentController()
move = cont.actuators[“move”]

press_w = cont.sensors[“W-Key”]
press_a = cont.sensors[“A-Key”]
press_s = cont.sensors[“S-Key”]
press_d = cont.sensors[“D-Key”]

#Diagonal WASD movement
press_wa = press_w + press_a #<-- Tried adding variables
press_wd = cont.sensors[“W-Key”, “D-Key”] #<–Thought this was a list

EDIT: I’ve tried just using this in the movement:

elif press_w.positive and press_a.positive:

and still no luck. There are no errors, but the character wont move in the direction I want even with both sensors positive.

Whole Script: pastebin: /cMDTZ9R1
[Fixed Script]: pastebin: /3z3iLSX7

I’m new to python but not programming, maybe I can help you out:

Edit: updated.
I cannot see any issue with your code (im not an expert, at all) and if your key presses are both returning positive then all should be good, however, I see no point in your Else if statements.

Your keys will either be pressed or not, it makes sense to check “If key.positive” but it does not (in my programming knowledge) make sense to use else ifs. Maybe try swapping them for if statements?

Let me know if it works or not so I can learn from it.

I just realized I was pressing the wrong keys facepalm (I only set the W/A Keys for diagonal movement - I was pressing W + D). I think turning the ‘elif’ statements to ‘if’ statements fixed the problem. Thank you!