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 audibles · Oct 15, 2013 at 01:59 AM · transformrotatevectorangles

How to rotate without a target vector

I'm feeling dumb. My desired effect is to rotate a sphere 45 degrees to the left, then 45 degrees to the right and then back to the original point in the middle. This rotation needs to be relative to the sphere itself, independent of world space.

So far all the solutions I've looked into involve assigning an object or point as the target for the rotation amount. Is there a clean way to accomplish this without a target?

If I'm just missing something super obvious somewhere, feel free to point me in that direction. Thanks!

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 s_guy · Oct 15, 2013 at 02:41 AM

I would use quaternion multiplication to determine your target rotation. You will need to convert Euler angles to quaternion. Left and right need a frame of reference in 3r space, so pick an axis where your 45 degrees will apply. Here's an example using the Z axis.

    float degrees = 45;
    Quaternion startRotation = transform.rotation;
    Quaternion endRotation = startRotation * Quaternion.Euler(0f, 0f, degrees);

Then, presuming you want to do this smoothly over time, you will need some means to iteratively progress to your target. I would use a coroutine. With each iteration, you could have Quaternion.Slerp() or an easing function to enact the incremental rotation each Update().

Take a good read over these reference pages:

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.html

http://docs.unity3d.com/Documentation/Manual/Coroutines.html

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StartCoroutine.html

Good luck!

Comment
Add comment · Show 3 · 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 robertbu · Oct 15, 2013 at 04:11 AM 0
Share

On the right track here, but order matters. Plus usually when you want a left/right rotation it means rotating around the 'y' axis. I believe you want:

 Quaternion endRotation = Quaternion.Euler(0f, degrees, 0) * startRotation;
avatar image s_guy · Oct 15, 2013 at 06:15 AM 0
Share

Order of multiplicands depends on what you're after, yes? The quaternion multiplication will first apply the left hand side, then the right hand side.

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion-operator_multiply.html

Since the original poster wanted a delta from the given starting orientation, this seems (experimentally too) to give the right result. Am I confused somehow?

avatar image robertbu · Oct 15, 2013 at 07:17 AM 0
Share

I'm not sure how to parse the web page you reference. Run the test yourself. Start with cube with a rotation of (45, 45, 45). Use Euler(0,45,0). When I the equation in the order I specified, I get (45, 90, 45). When I do them in the order you specified I get (8.42, 75.36, 59.64).

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

15 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

Related Questions

My object isn't rotating to the transform of another object. How do I fix this? 1 Answer

Rotating a bone via scripts 1 Answer

How do I control the transform.position of an instantiated prefab? 2 Answers

transform.rotate moving object away somehow, 0 Answers

Make a Move Vector rotate around axis to run animation. 0 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