Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Pbelling78 · Sep 01, 2011 at 12:52 AM · firingspacebar

Why can't i firing a bullet when holding down left and up arrow keys by pressing space?

I have coded a small game where you are stationary in the middle of the screen and you can hold down left arrow to fire left, up arrow to fire up, right arrow to fire...ETC

while i recently coded it that if you are holding both the up arrow and the right arrow you fire diagonally, every direction works (up/right, down/right, down/left) EXCEPT left/up

i wrote in a couple print statements and the game is reading me pressing down both the left and up arrow but the print statement within the firing code will not print so for some reason unity is no registering me pressing the space key when i have both the up and left arrow keys pressed....any help!?!?!!?

 if (Input.GetKey("right")){
     transform.Translate(Vector3.right * playerSpeed * Time.deltaTime);
 }
 if (Input.GetKey("left")){
     transform.Translate(Vector3.left * playerSpeed * Time.deltaTime);
 }
 if (Input.GetKey("up")){
     transform.Translate(Vector3.forward * playerSpeed * Time.deltaTime);
 }
 if (Input.GetKey("down")){
     transform.Translate(Vector3(0,0,-1) * playerSpeed * Time.deltaTime);
 }
 
 if (Input.GetKey("right") && Input.GetKey("up")){
     fireballScript.firingDirection = Vector3(-1,0,1);
 }
 //this is the one that is not working :-(
 if (Input.GetKey("left") && Input.GetKey("up")){
     fireballScript.firingDirection = Vector3(-1,0,1);
 }
 if (Input.GetKey("left") && Input.GetKey("down")){
     fireballScript.firingDirection = Vector3(-1,0,1);
 }
 if (Input.GetKey("right") && Input.GetKey("down")){
     fireballScript.firingDirection = Vector3(1,0,1);
 }
 
 if(Input.GetKeyDown("space")){
     Instantiate(fireBall, fireSpawn[fireDirection].position, fireSpawn[fireDirection].rotation);
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image em2 · Sep 01, 2011 at 01:09 AM 0
Share

Not in unity but in another program I had a similar problem, where it was testing if the keys were pressed but it was reading them at almost exactly the same time. I got around this by setting a boolean which was set if a key was pressed. i.e to 1 if the button was pressed and 0 if it was released. Therefore I was testing if both left$$anonymous$$eyPressed==1 && up$$anonymous$$eyPressed==1 then do something. This would only solve it if there were any issues if there is a problem with reading multiple keys in this case. Is it inside an update function? because as I understand it Get$$anonymous$$eyDown will reset at the next frame and wont be true again until the space bar is released and pressed again. Also, not a solution but in cases like this I have used switch ins$$anonymous$$d of multiple if's. Albeit probably not the answer I hope it helps a little. Cheers Chris

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by aldonaletto · Sep 01, 2011 at 04:18 AM

This is probably a limitation of your keyboard hardware. Keyboard keys form a matrix where each key connects a row to a column (8 rows and 16 columns, for instance). This arrangement allows detection of any two keys at the same time, but three or more keys may not be detected, depending on the rows and columns they connect. If three keys connect R1C1, R1C2 and R2C2, for instance, the circuit can't identify all of them because they short circuit all four lines when pressed at the same time.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aplocher · Jul 20, 2013 at 06:38 AM 0
Share

I found your answer quite fascinating. I'm having the same exact issue. As a test, I opened Notepad and tried the same key combinations: UP+RIGHT+SPACE, DOWN+RIGHT+SPACE, UP+LEFT+SPACE (all creates a space in the document), DOWN+LEFT+SPACE does not. This seems like a huge limitation in the hardware. How have I not noticed this before? So there's no work-around for something like this? If I played Zelda or something in an E$$anonymous$$U I would have the same problems? Thanks for the detailed response. PS, I would give you an upvote but I need 15 rep. Great answer.

avatar image aplocher · Jul 20, 2013 at 06:43 AM 0
Share

One more afterthought: I tried with the WASD keys and didn't have any problem at all. I like to give my users the choice of WASD or arrow keys, but it's so unfortunate that (at least with certain keyboards) users of the arrow keys will be at a disadvantage.

avatar image aldonaletto · Jul 20, 2013 at 02:06 PM 0
Share

Unfortunately, there's no workaround for this issue. Even worse, keyboards from different manufacturers may have different row/column assignments, thus the combination that works in a given keyboard may not work in another one. The keyboard designers usually avoid problems with the most frequent combinations like Ctrl-Alt-Del (PC), but there will always exist lots of "forbidden" combos with a matrix keyboard. The only way to avoid forbidden combos would be to have a keyboard chip with one input for each key, but this would be too expensive - specially nowadays, when everything is made in China with the lowest cost possible!

avatar image
1

Answer by Pbelling78 · Sep 01, 2011 at 04:44 AM

thank you aldonaletto, i kind of had a suspicion that it might be because of the keyboard but obviously wasn't for sure...i had no idea thats how a key board worked :-D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by dreammakersgroupAdmin · Sep 19, 2012 at 02:10 PM

I have same problem , what is this???

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create a light effect on weapon fire 0 Answers

Gun Turret Script. Help with distance C# Script 1 Answer

Hold Spacebar, Stop Jumping 1 Answer

Update() Function only fires once. 1 Answer

Projectile Hit Detection with Bullet Drop 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges