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 BrickForSheep · Aug 26, 2014 at 05:11 PM · rotationquaternioneulerinterpolation

Trouble Rotating Full-Circle

Okay, so this seems like a really ridiculous question, but for some reason, I'm having problems. I'm just trying to make an object perform a full rotation along a single axis. It's part of a basic interpolation script to handle linear animations. Basically, you input a start position/rotation, an end position/rotation, and an animation time and the script determines how to move between them. With this particular example, I'm trying to rotate the object from 360 degrees to 0 degrees in the X axis (the script only uses positive numbers for rotation values).

My object rotates fine from 360 to 270 degrees, at which point, things start to go wrong. If using transform.Rotate, when the X rotation hits 270, the Y and Z axes jump to -180.

 if ((openValue > closeValue && compareLeft < compareRight) || (openValue < closeValue && compareLeft > compareRight))
         {
             ...
 
             else if (transType == TransformType.ROTATE)
             {
                 gameObject.transform.Rotate(openSpeed, Space.Self);


While the rotation itself is still correct, it throws off the calculation for determining the rest of the rotation - when the object reaches its halfway point, it now reads as having performed a full rotation on the X axis because its rotation is now (0, -180, -180).

I originally tried to counter this by resetting axes in which no rotation is occurring to their start values, but that just causes the object to hit 270 degrees and then begin stuttering, not moving any farther.

 if (refAxis == AxisType.X)
                 {
                     if (closedCoords.y == openedCoords.y && gameObject.transform.localRotation.eulerAngles.y != openedCoords.y) { gameObject.transform.rotation = Quaternion.Euler(gameObject.transform.localRotation.eulerAngles.x, openedCoords.y, gameObject.transform.localRotation.eulerAngles.z); }
                     if (closedCoords.z == openedCoords.z && gameObject.transform.localRotation.eulerAngles.z != openedCoords.z) { gameObject.transform.rotation = Quaternion.Euler(gameObject.transform.localRotation.eulerAngles.x, gameObject.transform.localRotation.eulerAngles.y, openedCoords.z); }
                 }

So then, I tried to set the rotation value manually:

 gameObject.transform.rotation = Quaternion.Euler((gameObject.transform.localRotation.eulerAngles.x + openSpeed.x), (gameObject.transform.localRotation.eulerAngles.y + openSpeed.y), (gameObject.transform.localRotation.eulerAngles.z + openSpeed.z));

Using this example, however, the object rotates to 270 degrees and then stops. I've checked the target value I'm trying to assign, and it appears correct, but the script will not set the object to that orientation. If I soft-code those values in the Inspector, it's not a problem, but somewhere under the hood, Unity doesn't like what I'm trying to do.

How can I get around this?

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 robertbu · Aug 26, 2014 at 05:15 PM 0
Share

Any time you read eulerAngles, there is the potential for pain. Unity internally used Quaternions, and eulerAngles is derived from the Quaternion. There are multiple eulerAngles for any given physical rotation. For example setting (180,0,0) will come back as (0,180,180).

One trick is to treat eulerAngles as write-only. You keep your own Vector3 representing the rotation, and you make all of your modifications to that Vector3. You apply the Vector3 after you've made your modifications. That way you are always in control of the representation of the rotation.

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

2 People are following this question.

avatar image avatar image

Related Questions

How do you manually override mecanim's interpolation with rotations? 2 Answers

Quaternion.euler gives me glitch. Why? 1 Answer

Gun not rotating with the camera? 1 Answer

Weird rotation behaviour 1 Answer

Quaternion.Slerp problem... 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