Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Dendrake · Oct 22, 2014 at 09:32 AM · c#inputfixedupdate

W key is unresponsive with input

For some reason the W key only works every once in awhile on every computer but the one I built the project on which it works fine for.

 void FixedUpdate ()
 {
         if (Input.GetKeyDown ("w"))
             rigidbody2D.AddForce (Vector2.up * jumpHeight);
 }


Yes I know this means the gameobject can jump infinitely but it works fine for this game

Comment
Add comment · Show 2
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 Clastic · Oct 22, 2014 at 09:36 AM 0
Share

If you don't $$anonymous$$d me asking, where did you place this code? Is it in the "Update" function or in a different location? Just seeing the code and knowing that it works occasionally makes me think that you have working code that is placed in the wrong location... Or is imbedded in an if else statement within Update... If we could see more code that would be nice.

avatar image Dendrake · Oct 23, 2014 at 01:29 AM 0
Share

There, edited it to include where I made the call, I was told you should always put physics related code into FixedUpdate? I moved it to Update like two of the comments recommended and I am going to test it on another computer in a little bit. The issue I am having is that it works fine on my main laptop I use for things like Unity but as soon as I put onto another computer or laptop the key becomes unresponsive

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dimling · Oct 22, 2014 at 09:58 AM

There is nothing wrong with the code itself, so it must be the position of the code in the document that is the problem.

I applied the following script to a 2D sprite object and it works fine!

 public class TestScript : MonoBehaviour {
 
     
     public int jumpheight = 25; 
     
     
     void Start()
     {
 
     }
     
     void Update()
     {
 
         if (Input.GetKeyDown ("w"))
             rigidbody2D.AddForce (Vector2.up * jumpheight);
         
     }
 }

But remember: The GetDown method returns true during the frame the user starts pressing down the key. So it will only work for one click, or if you press multiple times it will look like a flappy bird game. If you want to get the object to keep moving while holding the button you can for instance use

 void Update()
     {
 
         if (Input.GetKey ("w"))
             rigidbody2D.AddForce (Vector2.up * jumpheight);
         
     }


Comment
Add comment · Show 2 · 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 JSierraAKAMC · Oct 23, 2014 at 02:35 AM 2
Share

And just for further explanation: your "Input.Get$$anonymous$$eyDown("w")" part was in a FixedUpdate, which means it only checks once per fixed frame (which is usually around 30-60 per second I believe). $$anonymous$$ost of the time, you do not press the key exactly when it checks, so no input is detected. This is why it sometimes worked and sometimes did not. In the future, I'd advise you put all of your input detection in "Update" so that it is checked every frame.

avatar image 4ntihero · Aug 20, 2015 at 03:44 AM 0
Share

I'm having this problem too. I put my jump function in Update() and it helped, but it still fails to pick up the key presses sometimes.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Missed key input 1 Answer

Why Do Inputs Have to Been in Update (Rather than FixedUpdate)? 3 Answers

Distribute terrain in zones 3 Answers

C# Touch Script - Fix GameObject touch. 0 Answers


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