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
0
Question by jmullen1 · Oct 22, 2021 at 01:30 AM · rotationrigidbodyforcetorque

Instant rotation bug when rotating clockwise

Hi there,

I am trying to use AddRelativeTorque to give smooth Z rotation to a game object:

  1. Rotate counter clockwise when given left horizontal input (pressing the "A" key or left on a left controller stick)

  2. Rotate clockwise when given right horizontal input (the "W" key or pressing right on a left controller stick)

  3. When given no input, rotate the game object back to default (in this case Z rotation = 0)

I'm also trying to limit the rotation, so that the force isn't added anymore when it hits a defined maximum rotation.

I have it working when rotating counter clockwise from 0 degrees towards 360 degrees. But weird things start happening, occasionally, when trying to rotate clockwise from 360 towards 0 degrees. Sometimes "transform.localEulerAngles.z" becomes negative for a frame or two and then my rotation jumps from 360 to my desired rotation (instant rotation):

alt text



Here is my code for rotating clockwise:

 if (Input.GetAxis("Horizontal") > 0) // Turn right (rotate clockwise)
 {
        if (transform.localEulerAngles.z > 360 - maxRotationZDegrees)
        {
            rb.AddRelativeTorque(new Vector3(0.0f, 0.0f, -1 * horizontalAxis * strafingRotationSpeed), ForceMode.Force);
        }
        else
        {
            // Set rotation to maximum and cancel accumulating force
            transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, 360 - maxRotationZDegrees);
            rb.angularVelocity = Vector3.zero;
        }
 }


I've been working on this problem and skimming unity forums for days and I still can't quite figure this out. I keep reading that local euler angles can't be negative but always stay within 0-360 degrees. Can anyone enlighten me why counter clockwise rotation (0-360 degrees) doesn't cause any glitches, but why clockwise rotation (360-0 degrees) can sometimes cause "transform.localEulerAngles.z" to be negative?



How can I get my z axis to rotate smoothly clockwise and not instantly jump from 0 degrees to the end goal rotation (maxRotationZDegrees)? Thank you.

negativeeuleranglez.png (46.9 kB)
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 jmullen1 · Nov 02, 2021 at 05:12 PM 0
Share

Even if someone could refer me to a similar bug / solution page I would be grateful. I haven't been able to find anyone else having a bug like this, but it it roadblocking my project currently. Any help would be much appreciated.

0 Replies

· Add your reply
  • Sort: 

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

253 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 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 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

How To Rotate Player with Rotating object 0 Answers

Access 2DCollision Torque/rotation force and set it to 0 0 Answers

Keep Rigidbody upright using torque. 1 Answer

Rolling platform affect player(ball) 1 Answer

Question about having a Rigidbody follow another GameObject via forces. 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