• 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 THEAK472009 · Jul 29, 2016 at 01:25 AM · euleranglesrotation axistransform.forward

Rotate object around transform.forward

Hello! I am trying to rotate an object around it's forward vector. But something is going wrong. This is what I did when the object's rotation is identity and the object has no parent.

• Rotate around local up vector by 90 degrees (now forward vector is (1,0,0) which is correct) • Rotate around local forward vector by 90 degrees (now forward vector should stay the same since I am rotating around the forward vector but it strangely changes to (0,1,0))

This has been blocking my progress quite a lot. Any sort of help will be really appreciated. Here is the code for the rotations. I have also tried it by concatenating quaternion rotations but it gives same result.

   private IEnumerator RotateAroundForward (int dir)
   {
     var t = 0.0f;
     var start = transform.localEulerAngles;
     var end = start + transform.forward * 90.0f * dir;
     while (t < 1.0f)
     {
       t += Time.deltaTime * rotateSpeed;
       transform.localEulerAngles = Vector3.Lerp (start, end, t);
       yield return null;
     }
   }
 
   private IEnumerator RotateAroundUp (int dir)
   {
     var t = 0.0f;
     var start = transform.localEulerAngles;
     var end = start + transform.up * 90.0f * dir;
     while (t < 1.0f)
     {
       t += Time.deltaTime * rotateSpeed;
       transform.localEulerAngles = Vector3.Lerp (start, end, t);
       yield return null;
     }
   }
 
   private IEnumerator RotateAroundRight (int dir)
   {
     var t = 0.0f;
     var start = transform.localEulerAngles;
     var end = start + transform.right * 90.0f * dir;
     while (t < 1.0f)
     {
       t += Time.deltaTime * rotateSpeed;
       transform.localEulerAngles = Vector3.Lerp (start, end, t);
       yield return null;
     }
   }

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 NoseKills · Jul 29, 2016 at 06:15 AM

Maybe my answer to this other question helps

Euler angles are often pretty useless if you do sequences of rotation around more than 1 axis.

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 THEAK472009 · Jul 29, 2016 at 09:42 AM 0
Share

Thanks man! This is perfect. Here is the code for anyone who needs this kind of rotation in all directions

   private IEnumerator RotateWorld (int dir, Vector3 _axis)
   {
     var startOrientation = transform.localRotation;
     var axis = transform.InverseTransformDirection(_axis);
     var end = 90.0f * dir;
     var t = 0.0f;
 
     while (t < 1.0f)
     {
       t += Time.deltaTime * rotateSpeed;
       transform.localRotation = startOrientation * Quaternion.AngleAxis($$anonymous$$athf.Lerp (start, end, t), axis);
       yield return null;
     }
     transform.localRotation = startOrientation * Quaternion.AngleAxis(end, axis);
   }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

51 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

Related Questions

Why is this rotation not performed as expected? 1 Answer

How edit transform.forward value ? 0 Answers

Transform.Rotate() rotation about one axis also rotates about the other axes 1 Answer

Eulerangles and Transform.forward... something's off? 1 Answer

Linking rotation on one local axis to another? 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