Before updating to Windows 10 you may need to return your Pro license. More information here

2 key combo problem.......


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
 if(Input.GetKeyUp(Keycode.W) && Input.getKeyUp(Keycode.A) ){
   change rotation of character to original
 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 leftalt text

more ▼

asked Sep 15, 2013 at 05:27 AM

avatar image

38 65 91 108

Please see this answer to clear out your confusion about the GetKeyXXX and GetButtonXXX family, how they work, when each version returns true, when false, etc. That should give you a better vision of what you're doing wrong.

Sep 15, 2013 at 05:32 AM vexe
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 ... http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html )

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!

more ▼

answered Sep 15, 2013 at 03:20 PM

avatar image

28.6k 346 713 432

well i'm not really a programmer. it's just a hobby . i dont have BA or BS or nothing i just picked up little stuff from around and i know alittle java so i am kinda discoveering how to do all this little by little

Sep 16, 2013 at 10:04 PM greatUnityGamer

i'm just the same, @great. Cheers!

Sep 17, 2013 at 06:55 AM Fattie
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Sep 15, 2013 at 05:27 AM

Seen: 540 times

Last Updated: Sep 17, 2013 at 06:55 AM