• 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 DoctorWhy · Dec 13, 2012 at 05:30 PM · rotationlocal

Local based rotation

I am not talking about simply setting the transform.localEulerAngles. But, when you use the rotation manipulator inside of the editor, and you set it to local, when you rotate something, it rotates exactly as expected. However, if you try and do a local rotation using transform.localEulerAngles, it still looks like a global rotation.

This is hard to explain, so you may just have to try this yourself to understand what I am getting at.

Say I want to rotate in the + local y. If I set localEulerAngles in code, because of the way Vector3s work, you have to set all 3. But, if you look at a local rotation in the editor, simply rotating in the local y changes more than just the y rotation. So how do I calculate the same type of local rotation?

Just so you can see my code, here is the rotation code. I am basically trying to create a rotation manipulator in game.

 //The local euler angles
 float x = startingRotation.x;
             float y = startingRotation.y;
             float z = startingRotation.z;
             
             Vector3 manipPos = ManipulatorCamera.WorldToScreenPoint(this.transform.position);
             
             float o = Vector3.Distance(Input.mousePosition, positionLastFrame);
             float a = Vector3.Distance(positionLastFrame, manipPos);
             
             float angle = Mathf.Rad2Deg*Mathf.Atan(o/a)*GetDirection(manipPos,Input.mousePosition,positionLastFrame);
             
             totalRotation += angle;
             
             switch(selectedManipulator.name)
             {
                 case "RotationRingX" :
                     x += totalRotation;
                     break;
                 case "RotationRingY" :
                     y += totalRotation;
                     break;
                 case "RotationRingZ" :
                     z += totalRotation;
                     break;
             }
             
             Debug.Log(x + " " + y + " " + z);
             
             Managers.SelectionManager.SelectedSmartPart.transform.localEulerAngles = new Vector3(x,y,z);
             
             positionLastFrame = Input.mousePosition;
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
0

Answer by danilonishimura · Dec 13, 2012 at 06:09 PM

As far as i know, Unity handle the rotation of the object using Quaternion and the displayed information is actually a conversion from the Quaternion rotation to the EulerAngles. If you need the values to do something, I'd suggest you to store the desired rotation in a Vector3 property and update the localEulerAngles in the "set" method.

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 DoctorWhy · Dec 13, 2012 at 06:14 PM 0
Share

What do you mean by "set" method? Do you know of any good tutorials on understanding Quaternion math? Working with the euler angles is a shit ton easier.

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

10 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

Related Questions

How to open and close a door parented to a rotating object? 0 Answers

Apply a Rotation in World Space based on Quaternions 2 Answers

Hotween - local Rotation 1 Answer

Help: Camera script sets Camera rotation always to World Rotation 1 Answer

mouse x not working when mouse y in use? 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