2 key combo problem.......

Hi.

So i have in update a check for
input release of 2 keys

It’s W+A at the same time

so first i have check to see if those were pressed. This is all in the update() method

if( Input.GetKey(Keycode.W) && Input.getKey(Keycode.A) )
  change rotation of character to diagonal
  return;
}


if(Input.GetKeyUp(Keycode.W) && Input.getKeyUp(Keycode.A) ){

  change rotation of character to original
 return;
}


if( Input.GetKey( Keycode.S) OR Input.getKeyUp(Keycode.S) {

    //move down(towards camera  in other words facing you    
    //the player)
}

The Problem is after i do the W+A combo. seems i have to exagerate my release of the keys in order to get the result that i programed in “keyUP” otherwise it doesn’t work. Is this common? i’m on a Mac.

If i release lightly softly, then it seems it doesn’t register that i have let the keys up.
Because sometimes for example i release the 2 keys and immediately follow an S for down.

And what happens is the character remains in the ROTATION i set for the W+A combo. and it does move towards the camera but it is facing stil diagonal and away from me. when the desired outcome is that at anytime when i press S(down, towards camera) the character should turn to face me.

So yeah, i have noticed, in order to make it work i have to release with exageration.
Is there a way to make it recognize my release of the 2 keys even if i release lightly?

Here’s a pic of what my game looks like. and i did the W+A combo to go diagonal forward to the left[15467-screen+shot+2013-09-14+at+10.23.39+pm.png|15467]

this is a very basic programming problem!

You simply can’t program computers unless you understand “state” - you have to know what “state” your game is in. (It’s just like the use of the term “state” in english - it’s not an arcane term.)

Here’s the solution:

(1) Have a boolean called “Both The A And W Keys Were Down”. Carefully notice the past tense.

(2) Have some code that does this: are both the A and W keys down? then, LOOK AT the boolean “Both The A And W Keys Were Down” if it is FALSE, then this means that “just now” the person held down the keys. Am I correct? I am correct. So, - again ONLY if it is false - call your routine “Do Something On AW”. Then, no matter what set “Both The A And W Keys Were Down” to be true.

(3) Thirdly and finally. Have some code that does this. Are BOTH of the A and W keys UP at the moment? If so, set “Both The A And W Keys Were Down” to be FALSE.

that’s it. it will work by magic, if you correctly implement those three paradigms.

It’s really a shame - actually maybe it’s not a shame - but so many new programmers are coming to Unity that there are lots of really non-unity-specific questions here!

BTW it’s worth noting that programming input is VERY VERY DIFFICULT

(one random example of hundreds … How to calculate swipe speed on iOS - Unity Answers )

it’s a hard art to master and there are huge paradigm decisions to make.

Anyway - you must think statefully or you can’t program computers. That’s your solution here!