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
1
Question by Murasame · Jun 08, 2011 at 09:54 AM · inputkeyboarddelay

unbuffered keyboard input delay

Hello,

I'm having a weird issue of input delay with Input.GetAxis(). I had not this issue before, suddently appered after writing a kind of complex script so I wrote back a simple script and the behavior is still present... I have like half of seconde of input delay when pressing a key.

My scene is basic, its just a cube with box collider and rigibody on top of a flat terrain, I'm directly setting the velocity so I doubt it has anything to do with friction or stuff like that.

Here the script:

 function Update(){
 
     if(Input.GetAxis ("Horizontal") == 1)
         rigidbody.velocity.x = speed;
         
     else if(Input.GetAxis ("Horizontal") == -1)
         rigidbody.velocity.x = -speed;
 
     else
         rigidbody.velocity.x = 0;
 }

Thank you.

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 Owen-Reynolds · Jun 10, 2011 at 06:57 PM 1
Share

That lag is a feature of GetAxis. You can set the rise/fall speed (in the Input $$anonymous$$anager) so it gradually ramps up to 1 however fast you want it to.

avatar image Chris D · Jun 10, 2011 at 07:01 PM 0
Share

@Owen Reynolds - now that I did not know; thanks!

2 Replies

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

Answer by terdos · Jun 10, 2011 at 06:10 PM

Try GetAxisRaw as it will output -1, 0, 1. GetAxis will smooth the input, which may take up to half a second to reach the maximum.

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 Murasame · Jul 13, 2011 at 07:54 AM 0
Share

Sorry for late response, and thank you very much, this did the trick.

avatar image Harinezumi · Mar 03, 2018 at 07:53 PM 1
Share

6 years later, and this answer is still the solution :)

avatar image
2

Answer by Chris D · Jun 10, 2011 at 06:29 PM

Alternatively, you could use:

 function Update(){
 
     if(Input.GetAxis ("Horizontal") > 0)
         rigidbody.velocity.x = speed;
 
     else if(Input.GetAxis ("Horizontal") < 0)
         rigidbody.velocity.x = -speed;
 
     else
         rigidbody.velocity.x = 0;
 }

to accomplish the same thing as in @terdos 's answer but still allow for an analog input somewhere down the line (if that's what you're after).

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 Joshua · Jun 10, 2011 at 06:40 PM 0
Share

[edit]See you've edited the answer, so never $$anonymous$$d ;)

avatar image Chris D · Jun 10, 2011 at 06:46 PM 1
Share

Oops, Thanks for catching that! The point I was trying to make is that you can still use the smoothed values of GetAxis but, as per @terdos 's answer, the function may not immediately return a 1 or -1 value and ins$$anonymous$$d be somewhere between 0 and +/-1.

avatar image Murasame · Jul 13, 2011 at 07:55 AM 0
Share

Thank you this solution work too, althrough using GetAxisRaw allow me to write smaller code by using it directly in the equation.

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

7 People are following this question.

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

Related Questions

How to prevent input lag/delay? 1 Answer

How do I fix the input delay on Unity for Mac? 0 Answers

Animation delay until certain distance 3 Answers

Unity Thinks I Have Z Instead of W Button 1 Answer

Checking whether string is a valid Input.Key 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