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 DRProductions · Jan 19, 2014 at 08:30 PM · rigidbodyinputglitchkeypress

Odd input glitch

I have a script that toggles the drag of a physics object while x is held down and then when x is released it returns the drag to 0. The problem is that sometimes the key presses don't register, sometimes it wont register that the button is pressed and other times it won't recognize the key is released anyone see a problem with my code? Here is the related code:

 function FixedUpdate () {
 if(Input.GetKeyDown("x")){
 Brake(true);        
 }
 if(Input.GetKeyUp("x")){
 Brake(false);        
 }
 }
 
 function Brake (Down){
 if(Down){
 rigidbody.drag =  1;
 }
 else{
 rigidbody.drag =  0;
 }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by BigRoy · Jan 19, 2014 at 10:03 PM

Use the Update() method instead of FixedUpdate().

The documentation states:

You need to call this function from the Update function, since the state gets reset each frame. It will not return true until the user has released the key and pressed it again.

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKeyDown.html

See also:

http://answers.unity3d.com/questions/302814/placing-inputgetkeydown-inside-fixedupdate-slows-d.html

http://answers.unity3d.com/questions/270552/not-sure-if-this-should-go-in-update-or-fixedupdat.html

http://answers.unity3d.com/questions/256271/intermittent-detection-of-input-in-fixedupdate.html

http://stackoverflow.com/questions/19259097/is-it-really-wrong-to-use-input-getkey-on-fixedupdate

Comment
Add comment · Show 1 · 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 DRProductions · Jan 19, 2014 at 10:04 PM 0
Share

I have tried that before, no effect whatsoever. Edit, Never$$anonymous$$d you are right it seems when I did that before i must not have saved the script so I saw no changes FacePalm

avatar image
0

Answer by Yusaku · Jan 19, 2014 at 09:06 PM

I think you have some extra {and} in there could be wrong but thats what it looks like. Fix that first and see if it helps. Sorry my bad i was wrong. I dont know whats going on!

Comment
Add comment · Show 1 · 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 DRProductions · Jan 19, 2014 at 09:43 PM 0
Share

Thanks for trying, this is getting annoying ahh I really hate bugs

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

19 People are following this question.

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

Related Questions

Can't move player with rigidbody.velocity 1 Answer

AddTorque doesn't rotate? 3 Answers

Making a ship move 1 Answer

Key reading from inputString, backspace only works the first time 4 Answers

How do i get the cube to turn when up and right or left arrow is pressed? 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