• 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 Jappehh · Dec 21, 2020 at 10:58 AM · smoothgetaxis

New input System GetAxis alternative

Hi, I'm making a game where my player needs to accelerate so I need the vector2 to go smooth from 0 to 1, now it just goes from 0 to 1 instantaneous like the old "GetAxisRaw", setting the mode too analog does not work. Is there a way I can make it go smooth like "GetAxis"? Thx for your answer!

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

1 Reply

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

Answer by Pokedlg3 · Dec 21, 2020 at 12:53 PM

You can use transform.Translate and time.deltaTime to soften the effect of GetAxis, look at an example:

     if(Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
     {
         transform.Translate(10*Time.deltaTime,0,0);
     }
     if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
     {
         transform.Translate(10*Time.deltaTime,0,0);
     }
     if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
     {
         transform.Translate(-10*Time.deltaTime,0,0);
     }
     if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
     {
         transform.Translate(-10*Time.deltaTime,0,0);
     }

the Time.deltaTime, leaves the movement smooth, replicating the effect of GetAxis, now if you want to get the effect of GetAxisRaw, just remove Time.deltaTime.

     if(Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
     {
         transform.Translate(10,0,0);
     }
     if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
     {
         transform.Translate(10,0,0);
     }
     if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
     {
         transform.Translate(-10,0,0);
     }
     if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
     {
         transform.Translate(-10,0,0);
     }
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 Jappehh · Dec 21, 2020 at 01:32 PM 1
Share

Thx for your answer, this helped a lot!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Smooth transition for GetAxis, when pressing opposite direction 1 Answer

Get smooth input when Time.timescale == 0 1 Answer

Animation speed control - no smooth animation on slow down 3 Answers

2d camera help! 0 Answers

Turn page, smooth rotate 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges