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
0
Question by leonalchemist · Sep 19, 2014 at 05:57 PM · rotationdamping

Strange damping issue[solved]

i have this problem where a spaceship rotation can move around a tube left or right, the ship rotates left and right fine but when i let go of the button i want a smooth stop, a bit weird to explain but basically the damping works when i let go of the right key but not the left, im probably doing a basic math error so any ideas?

         if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
         {
             rotation = -300;
         }
         else if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
         {
             rotation = 300;
         }
         if(rotation > 0)
         {
             rotation -= 1500 * Time.deltaTime;
         }
         else if(rotation < 0)
         {
             rotation -= 1500 * Time.deltaTime;
         }
         gameObject.transform.eulerAngles.z += rotation * Time.deltaTime;

alt text

101.png (15.9 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
1
Best Answer

Answer by dmg0600 · Sep 19, 2014 at 06:07 PM

Could it be that you are substracting to the rotation even when it is below 0?

Change:

 if(rotation > 0)
 {
     rotation -= 1500 * Time.deltaTime;
 }
 else if(rotation < 0)
 {
     rotation += 1500 * Time.deltaTime;
 }

Haven't actually tried on the editor but it seems that is the problem.

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 leonalchemist · Sep 20, 2014 at 12:51 PM 0
Share

i tried changing most these + to - and test around but without much luck, i dont really know wats the problem though?

avatar image dmg0600 · Sep 22, 2014 at 09:03 AM 0
Share
 Vector3 euler = gameObject.transform.eulerAngles;
 
 if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow) || Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
 {
     rotation = -300;
 }
 else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow) || Input.Get$$anonymous$$ey($$anonymous$$eyCode.D))
 {
     rotation = 300;
 }
 if (rotation > 0)
 {
     rotation -= 1000 * Time.deltaTime;
 }
 else if (rotation < 0)
 {
     rotation += 1000 * Time.deltaTime;
 }
 
 if (rotation > -10 && rotation < 10)
 {
     rotation = 0;
     euler = Vector3.zero;
 }
 
         
 euler.z += rotation * Time.deltaTime;
 gameObject.transform.rotation = Quaternion.Euler(euler);


This is what I meant, you were substracting ins$$anonymous$$d of adding when rotation < 0. This way you will have the same effect on both directions.

avatar image leonalchemist · Sep 23, 2014 at 12:05 AM 0
Share

should have probably changed that, but like i said, i've seen and tested that before but didn't work at all, tested your code also but teleports my player when i let go of the button, dont think those added lines are necessary for my case; still same issue as before unfortunately :/

avatar image leonalchemist · Sep 23, 2014 at 12:16 AM 0
Share

Ghah! never$$anonymous$$d :/ found the problem which you couldn't have known.. had a stupid $$anonymous$$athF.Clamp on my rotation limiting it from 0 to 300 ins$$anonymous$$d of -300 and 300.. noob mistake, sry bout that and thx for the help regardless

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

25 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

Related Questions

Smoothing eulerAngles rotation? 1 Answer

Flip over an object (smooth transition) 3 Answers

Smooth rotation on one axis only 2 Answers

Rotate Camera in Increments with Damping 2 Answers

A way to kill rotation made by rigid body pysics? 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