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 Okido · Oct 16, 2014 at 10:38 PM · c#rotationeulerangles

How to smoothly rotate an object through just one axis

Hi,

**Edit:* I've changed my question as I need to rotate an object smoothly through just one axis, and realise that I am probably going about this in the wrong way by using Quaternion.Slerp, etc. Any advice on how to achieve this is most welcome. I have still left my original question below to give you a picture of where I'm going wrong.

I'm rotating an object with Quaternion.Slerp, and then checking if it is finished by using Quaternion.Angle. and using an if statement to check if it's reached its destination. Once it reaches its destination it will stop trying to Slerp to it. My problem is that I only need to check one or two of the axes (it should just be the one axis I need to check if my logic serves correctly!)

My code is simply this:

 if(Quaternion.Angle(toUpsideDown.rotation,transform.rotation) == 0){ 
            FinishedRotation();
     }

How can I isolate/exclude individual axes from Quaternion.Angle? I only want to know when the x and y have reached their destination, I don't want it to wait for z as well as this causes behaviour that I don't want (I want it to keep facing the same direction when it is rotated, no matter where it is looking - not be forced to turn and face north, for example)

My destination in Quaternion.Angle is a Transform variable (called toUpsideDown as the object is rotated to be upside down), and to use it I drag an empty GameObject into the inspector which is at the right orientation.

If I cannot achieve this with Quaternion.Angle, what other methods can I use?

Thanks!

Comment
Add comment · Show 3
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 Owen-Reynolds · Oct 17, 2014 at 05:34 AM 0
Share

I don't think it works that way. A slerp just goes straight from one facing to another. Every "axis" gets there at the same time.

Usually with problems like this, it's a matter of figuring out what you really want to do.

avatar image Okido · Oct 17, 2014 at 09:45 AM 0
Share

You're probably right, I hope I can figure it out with some help. What I really need to do is smoothly transition 90 degrees through just one axis. I knew how to use Lerp to move an object, but I'd read that to smoothly rotate an object, you need to use Quaternion.Slerp? So, is there another way to "lerp" between rotations without having to influence all three axes? I am still learning to program so there's likely something to do this that I haven't heard of.

avatar image HarshadK · Oct 17, 2014 at 09:53 AM 0
Share

$$anonymous$$athf.LerpAngle

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by quantumface · Oct 17, 2014 at 01:03 AM

You wrote Quaternion.Slerp at the start, and Quaternion.Angle the rest of the post. Confusing. But from the documentation of both, you can see that they use start and end positions as Quaternions. And you can replace those quaternions pretty much with Vector3(x, y, z), so you can just use your own values on any of the axes you need. I hope makes sense? :)

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 Okido · Oct 17, 2014 at 09:34 AM 0
Share

Ah sorry, I meant that I am slerping the object with Quaternion.Slerp, then using Quaternion.Angle to check if the slerp is finished. Could you give an example of how to replace the Quaternions with my own values?

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

30 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Getting the rotation of an object does not return correct rotation 1 Answer

Rotation of player not working 0 Answers

Rotation jumping to a different rotation after rotating a certain amount 0 Answers

Distribute terrain in zones 3 Answers


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