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 Aladine · Mar 21, 2015 at 02:29 AM · rotationquaternion

How to rotate Quaternion around axis for a certain degree

Hello, Please take a look at this animated picture : alt text

What i want to do is to rotate the cube around one of the axis but most importantly stop it at a certain point, in this case is when the cube become orange. I know how to rotate the cube :

 transform.rotation *= Quaternion.Euler (Vector3.right * speed * Time.deltaTime);

I want to know what to use in order to calculate when to stop (1/4 way in my case), i am not used with working with quaternion so any further explanation would be really appreciated.

thank you and have a nice day

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by siaran · Mar 21, 2015 at 02:24 PM

Well, you could just check your transform's euler angles before and after the rotation, add the difference to some variable, and stop rotating if that difference reaches a certain number.

Or, you could calculate how long you need to rotate at the speed you are rotating. With the code you have you are essentially rotating speed degrees per second, so you can calculate how long you need to rotate, and stop rotating when that much time has passed.

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 Aladine · Mar 21, 2015 at 02:44 PM 0
Share

Thanks siaran, yeah that's what i did, it turned out i was facing problems because of my initial rotation setting ^^

avatar image
0

Answer by Aladine · Mar 21, 2015 at 02:43 PM

i kinda fixed the problem by setting the initial rotation of the object to (0,45,0) and instead of rotating the object to show the upper face of the cube, i moved and rotated the camera to have the same view. Like this i was able to just add 90degrees to X or Z and have the result am looking for, however, i have a new simple problem, the cube reverse its rotation direction every time, it goes to the correct rotation, but in a reversed direction, here is a GIF : alt text

and this is my code :

 using UnityEngine;
 using System.Collections;
  
 public class RotateCube : MonoBehaviour
 {
  
         public  float speed;
         private Vector3 myEul, targetEul;
         private Transform myTrans;
         private bool canRotate;
  
         void Start ()
         {
                 myTrans = transform;
                 myEul = myTrans.rotation.eulerAngles;
                 targetEul = myEul;
  
         }
        
  
         void Update ()
         {
        
                 if (canRotate) {
                         rotationInput ();
                 }
                 checkRotation ();
         }
  
  
  
         void checkRotation ()
         {
                 if (Vector3.Distance (targetEul, myEul) > 1.5f) {
                         myEul = Vector3.Lerp (myEul, targetEul, speed * Time.deltaTime);
                 } else {
                         myEul = targetEul;
                         canRotate = true;
                 }
                 myTrans.rotation = Quaternion.Euler (myEul);
         }
  
  
  
         void rotationInput ()
         {
                 if (Input.GetKeyDown (KeyCode.LeftArrow)) {
                         myEul = myTrans.rotation.eulerAngles;
                         targetEul = myEul;
                         targetEul.x += 90;
                         canRotate = false;
                 }
         }
 }

Thank you :)

Comment
Add comment · 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

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

21 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

Related Questions

how to combine 2 quaternion components? 2 Answers

Transform a Vector by a Quaternion 1 Answer

Change the roll of the rotation 0 Answers

How to ROTATE an object without slowing the ends (lerp) 3 Answers

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 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