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 /
  • Help Room /
avatar image
6
Question by JtheSpaceC · Mar 08, 2015 at 03:55 PM · 2dmovementtop down

Character keeps moving a moment after I release input keys

I've searched but not found my exact problem so here it is:

Top down 2D game with a sprite character moving forward/backward/strafing with WASD/arrow keys. He looks at mouse. I move him with the following code (in Update). Using Unity 5.

         transform.Translate ((transform.up*Input.GetAxis("Vertical") + transform.right*Input.GetAxis("Horizontal")).normalized *speed*Time.deltaTime);
 

The code works to move the character but the problem is the character keeps moving for about a half second after the input keys are released. This gives the controls a very unresponsive feel and the character seems as if he's slipping across the floor.

If I only tap the key, the effect isn't so bad, but if I hold it at all I get the problem. I should mention that if I hold the key for 1 second or for 60, he'll stop moving after the same amount of time (about a half second). It doesn't get worse the longer I hold, is what I mean to say.

Is there a better way to move the character? Put code in FixedUpdate but had the same problem.

Thanks for any help provided.

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

3 Replies

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

Answer by S_Darkwell · Mar 08, 2015 at 10:10 PM

That's because Input.GetAxis() returns a smoothed output.

Try using Input.GetAxisRaw(). Eg:

 transform.Translate ((transform.up*Input.GetAxisRaw("Vertical") + transform.right*Input.GetAxisRaw("Horizontal")).normalized *speed*Time.deltaTime);

Hope that helps!

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 BoomerandZiggy · Aug 06, 2015 at 07:57 PM 1
Share

This fixes what I was looking for exactly. I think i see a lot of other posts about unity controller physics so I dont know how it works but my inclination is to say vote this answer up. Also do you know how to manipulate the smoothing so that i can set it to get something in the middle. I'll look myself also and post here if i find it.

avatar image Sphynxe · Oct 04, 2017 at 12:26 PM 1
Share

Excellent, just what I needed!

avatar image
7

Answer by bradclovell · Sep 05, 2016 at 08:28 PM

S_Darkwell's answer is right on, but there is also another solution besides Input.GetAxisRaw()

Although Input.GetAxis() returns a smoothed output that reaches 1 and -1 somewhat slowly and returns to 0 somewhat slowly, this can be sped up in the Edit/Project Settings/Input menu.

If you look at your axis, in the InputManager, there are options for Gravity and Sensitivity. Sensitivity is how fast the output reaches 1 or -1 Gravity is how fast the output returns to 0

If you raise these values, you can have smoothed GetAxis() input that is much more responsive.

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 IAMBATMAN · Oct 12, 2016 at 09:40 PM 0
Share

Thanks so much! It's perfect :)

avatar image
0

Answer by JtheSpaceC · Aug 07, 2015 at 11:28 AM

I believe it worked better in FixedUpdate for me in the end, though this is an old project for me now..

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

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

Can't seem to get collision to work among my sprites 1 Answer

Mobile Left and right move input for the player in 2D (Top Down) 0 Answers

moving an object on the y and x axis to mouse location 0 Answers

Unity2D How to dodge roll? 0 Answers

2D upward curve movement? 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