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 NosVidz · Mar 30, 2016 at 08:33 PM · movementinputdirectioninputmanager

Horizontal/Vertical input immediately zero after key release

Hi.

I use the horizontal/vertical input axis to change the direction of the player. Therefore I want the direction to change immediately after the button is released. The problem is that after release, the value for the axis will slowly fall from 1 (or -1) to 0, which causes the change in direction to trigger about a second too late.

I thought about checking if the value for the axis is 1 / -1, and changing the direction if it isn't (that would be the case after release of the button), but then I would have the same problem for the beginning (When I press the button, the value slowly increases from 0 to 1.

Another idea was to handle the movement via script (With KeyUp / KeyDown events), but I want the player to have the dynamic key allocation of the Input manager (otherwise I could simply check for WASD or arrow keys). So is there a way to

a) Set the value of the axis to 0 after the key is released

or

b) Get the buttons which are allocated for the horizontal / vertical input axis

Thanks

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 NosVidz · Mar 30, 2016 at 05:17 PM 0
Share

I forgot: If there is a way to only have -1, 0 and 1 as input values (without the slopes), that would not be possible, because I need those values in between for a smooth acceleration.

1 Reply

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

Answer by Bunny83 · Mar 31, 2016 at 01:57 AM

That's pretty simple. Just open up the Input manager in Unity and assign a high gravity value for your input axes. Gravity is the "speed" for "falling to neutral" and "Sensitivity" is the speed for the acceleration.

Further more you can also tick the "snap" checkbox if you want. It will snap the value back to neutral whenever the player switches to the opposite key. Usually when you switch the direction without ever releasing both keys, the value will only be affected by sensitivity. So it you have a relatively slow acceleration it takes some time to actually fall back to neutral before you actually accelerate into the opposite direction. Snap will ensure you start accelerating at "0" / neutral.

Say it takes 1 sec to accelerate to the value "1.0" (which means you have a sensitivity of "1" unit per sec.). If you press the positive button it will accelerate and reach the value of 1 after 1 sec. If you now switch the direction (press the negative button at release the positive) you will "accelerate" into the opposite direction. However since the current value is 1.0 it takes 1 sec to actually reach 0 before the value actually becomes negative. With "Snap" enabled the value immediately returns to 0 when you switch an start accelerating from there.

Comment
Add comment · Show 6 · 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 Eno-Khaon · Mar 31, 2016 at 02:12 AM 4
Share

Additionally, Input.GetAxisRaw() specifically ignores the gravity and sensitivity values applied to the input. This can be handy for situational 1:1 feedback from your controls.

avatar image NosVidz · Mar 31, 2016 at 01:14 PM 0
Share

Exactly what I wanted, and awesome explanation. I didn't know what gravity and sensitivity are, but now I do! Thanks.

avatar image meat5000 ♦ NosVidz · Mar 31, 2016 at 01:29 PM 0
Share

Such things are always found in the manual.

avatar image Karaflakos21 · Apr 17, 2017 at 11:26 PM 0
Share

I tried setting the gravity to a high value but it looks like it's not doing anything. I keep getting my walk animation after releasing the "w" key.

avatar image frencrus78 · Apr 05, 2020 at 04:17 PM 0
Share

IT DON'T WORK. IT IS A UNITY BUG!

avatar image erasergame frencrus78 · Oct 11, 2020 at 04:09 PM 0
Share

Is there a way around the bug... I $$anonymous$$ean any solution you know about it!!! If you know then also pls let me know...

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

9 People are following this question.

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

Related Questions

Determining movement direction through crosshair 2 Answers

Holding Ctrl prevents character from moving 2 Answers

help with direction 1 Answer

Left Shift being cancelled by left control? 1 Answer

InputManager doesn't detect gamepad numbers correctly 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