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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by iamMichaelDavis · Feb 05, 2014 at 03:28 PM · axisinputmanagerkey pressed

Can I reset the InputManager's Axes with a script?

By default, the Horizonal Axis in the InputManager is set to the right key is positive and the left key is negative. If you hold down the left key, the value of the Axis goes down to -1 and then stays there as long as you hold down the left key.

Is there any way to tell the InputManager to reset itself, and ignore any keys that may be held down? For instance, if someone was holding down the left key, and the Horizontal Axis was at -1, just resetting the Horizontal Axis to 0 and ignoring the left key until it's released and pressed again?

Follow up question: if it isn't possible, is it possible to "spoof" an Input.GetKeyUp event on a specific key? Can you tell Unity the left key was lifted even if it wasn't?

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 · Feb 05, 2014 at 05:37 PM 0
Share

What was wrong with Input.ResetInputAxis();? I'm assu$$anonymous$$g something was, since it's the top result from searching "unity reset input."

The scripting docs says it snaps to 0's, and something about buttons for only 1 frame. But the text implies it clears a held-down button. I've never tested it.

avatar image iamMichaelDavis · Feb 06, 2014 at 04:33 PM 0
Share

What was wrong with the answer button? Is it just more fun to knock down newbs in the comment section? And we'll have to agree to disagree on the first results for "unity reset input", my first results are:

http://answers.unity3d.com/questions/471506/how-to-reset-games-built-input-controls.html http://answers.unity3d.com/questions/213986/how-to-reset-users-input-settings.html http://answers.unity3d.com/questions/35477/how-can-i-restore-input-settings.html

$$anonymous$$aybe that's why I asked a question, on this question and answer site.

Finally: there is no ResetInputAxis. There IS a ResetInputAxes, which resets ALL axes (plural). Fortunately that'll still work for me, so thanks for letting me know about it! If only there was some way I could give you credit or appreciation for answering a question I had. Oh well.

2 Replies

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

Answer by iamMichaelDavis · Feb 06, 2014 at 04:58 PM

Input.ResetInputAxes(); will reset all the Axes to 0

(thanks to Owen Reynolds for the answer :) )

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 FunkyL1zard · Feb 05, 2014 at 03:57 PM

I'm not sure that you can reset the InputManager's Axes, however you can use Input.GetMouseButtonDown and Input.GetMouseButtonUp instead of it. You can Invoke a action that will do something even if the mouse button is still down.

 float delay; // Delay before Activity is called
 void Update(){
 if(Input.GetMouseButtonDown(0)){
 Invoke("Activity", delay)
 }
 if(Input.GetMouseButtonUp(0)){
 Activity();
 }
 }
 
 void Activity(){
 }

The Activity will still be called even if you don't release the mouse button.

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 iamMichaelDavis · Feb 06, 2014 at 04:50 PM 0
Share

I was running into a bug in my beginner's first try state machine I made where if you pressed the right key (`Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.RightArrow);`) my player character would start walking right, and the amount it would move would be multiplied by the amount of the input:

transform.Translate (Vector2.right * Input.GetAxis ("Horizontal") * egoSpeed * Time.deltaTime);

And every update the state machine checks to see if the key is still down (`Input.Get$$anonymous$$ey ($$anonymous$$eyCode.RightArrow);`) and if it is it keeps walking right. Once you let go of the right key, the walking stops, and it begins to listen for key press events again.

However, if you press and hold right, THEN press and hold left, then let go of the right button, my player stops walking, but the held down left key sets the Horizontal axis to -1. When you press right again (still holding left) the "walk right" animation begins, but the player's direction is multiplied by -1, making him moonwalk.

With Input.ResetInputAxes(); running when the right key is released (`Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.RightArrow);`), the input is reset when you let go of the right key, and the very next frame the game assumes the held down left key is just now being pressed, and turns the character left.

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

20 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 avatar image

Related Questions

Get list of Axes? 4 Answers

Steelseries 3gc controller key mappings 0 Answers

Button Axis with New Input System 0 Answers

Will Unity 3.0 have a scriptable Input Manager 1 Answer

Make ball flip around cube... 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