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 /
avatar image
2
Question by Sonaten · Nov 02, 2012 at 03:09 PM · smoothinput.getaxisgetaxisinterpolationinterpolate

Smooth transition for GetAxis, when pressing opposite direction

I am currently working on a space game (sideways look, scrolling top down). I am using Input.GetAxis("Horizontal"), for input to controlling multiple behaviors for a space rocket. GetAxis seems smooths from zero to 'some value' when pressing a key, and from this value back to zero as it is released. One of the things I am using the result of GetAxis to, is handling an EulerRotation of the space ship.

It works decently most of the time, but I am not satisfied with the result of pressing one key for one direction, and then pressing the one for the opposite directions, as this resets the GetAxis value to zero at the occurance. The result of this is attempted illustrated in the added figure below.

First scenario is a simple, and the angles smoothly turns the rocket. Second scenario forces a bigger jump in the eulersangles.

Jumpy angle shift. This is an issue as I would like to have some very polished mechanics.

I am looking for a way to disable the result of pressing 'd' whilst the rocket is tilted counter clockwise (in context of the example). Either that, or some interpolation for the values, so that 'smoothness' is preserved. Any input on this, methods or direct solutions, are appreciated.

Thanks in advance.

P.S. I program in C#, but understand JS easily.

smoothgetaxis.png (127.5 kB)
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
6
Best Answer

Answer by Loius · Nov 02, 2012 at 05:02 PM

in edit > project settings > input, disable the 'snap' checkbox on the axis in question

Comment
Add comment · Show 4 · 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 Sonaten · Nov 02, 2012 at 06:48 PM 0
Share

Thanks a bunch, this results in the wanted behaviour. I am however still interested in a solution that takes to interpolating a current value towards the new one. If you could enlighten me on such a method as well I would be very much obliged.

avatar image Loius · Nov 03, 2012 at 05:32 PM 0
Share

Usually I do that by storing an 'actual' rotation and a 'target' rotation, and use an acceleration to move towards the target rotation.

Something like:

 var actual : float; var target : float; var accel : float = 25;
 function Update() {
   actual += accel * $$anonymous$$athf.Sign(target-actual) * Time.deltaTime;
   transform.rotation = Quaternion.Euler( 0,actual,0 );
   target = 45 * Input.GetAxis("Horizontal");
 }

But I believe the 'gravity' setting (in the Input manager also) can effect the same... effect, but automatically, if you don't need fine control over it. Gravity makes the axis's return value move slowly from point to point ins$$anonymous$$d of instantly being what the player has input.

avatar image Sonaten · Nov 12, 2012 at 10:48 PM 0
Share

Thanks a bunch, appreciate your input.

avatar image Ishkur · Feb 28, 2014 at 09:15 AM 0
Share

This is exactly what I needed! I can't believe it was a built in option, I've been worrying about trying to script a solution to this all this time!

Thanks to Sonaten for asking the question and Loius for answering!

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

11 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

Related Questions

Smooth camera size interpolation 1 Answer

Tracking slow mouse movements 1 Answer

How do I get a value from Input.GetAxis() ? 1 Answer

How to interpolate or polyfit two data sets? 0 Answers

How to rotate an RigidBody2D object to an angle and get back to the previous position in the smooth way? 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