- Home /
Cannot use Inputs up/left and space?
Only the up/left arrow keys will not work... It does, however, work with w/a keys and all other combinations of arrow keys? What is going on....?
if ( Input.GetAxisRaw ( "Horizontal" ) != 0 & Input.GetAxisRaw ("Vertical") != 0 & Input.GetKeyDown ("space") )
{
print("t");
}
This is the code I used.
Thanks!
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftArrow) || Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.RightArrow) || Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)) {
print("t");
}
Answer by aldonaletto · Jun 14, 2012 at 02:43 AM
A single & is the bitwise AND operator - from your code, I suppose you actually want the logical AND (&&):
if (Input.GetAxisRaw("Horizontal") != 0 && Input.GetAxisRaw("Vertical") != 0 && Input.GetKeyDown ("space")){
print("t");
}
This code will print "t" when both axes are non-zero and the space bar is pressed - in other words, when pressing A or D and W or S and Space.
NOTE: Regular PC keyboards can report any two keys pressed at the same time, but 3 or more keys may not be correctly detected.
Well, I just found out that on some keyboards, that input will not work - something called ghosting. I was wondering what you mean by bitwise AND operator?
Thanks!
@TobiasP: He means they're for binaries (0011 for example). For booleans, you generally use boolean operators (||, &&).
Yes, & is the binary AND: each bit in one operand is ANDed with the corresponding bit in the other operand. But the keyboard problem is due to the way keys are detected: there's a matrix where each key connects one row to one column. This system allows detection of any two keys at the same time, but 3 or more keys may short circuit two columns and two rows, producing the wrong codes.
Your answer
Follow this Question
Related Questions
Movement axis different on client than on server? 1 Answer
VR: Manipulate Input for Continous Movement Provider // Create "Arm Swing Locomotion" 0 Answers
GetButtonDown is unresponsive 0 Answers
How to fix player jumping while watching downwards and moving with s key ? 1 Answer
Inputs cutting eachother out 1 Answer