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 oliver-jones · Mar 29, 2013 at 11:32 PM · javascriptquaternionrotate

Rotation - Why doesn't this work?

When I'm working with object rotations via script, it always seems to be a hit or miss situation.

All I'm trying to do, is have my script to change the rotation of my object on the X axis by ONLY 10

 leftTail.transform.rotation = Vector3(10,0,0);

It just seems to get unnecessarily confusing with Unity involving Quaternions.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by aldonaletto · Mar 29, 2013 at 11:53 PM

That's not a Quaternion's fault: rotations are always confusing in a 3D world. A quaternion actually is a rotation of some angle about an arbitrary axis - it's thus a simple angle-axis rotation, coded in a convenient way (convenient for mathematicians, of course).

In this case, if you want to simply rotate 10 degrees about the local X axis, use Rotate:

 leftTail.transform.Rotate(10,0,0);

If you want to rotate about the global X axis, specify Space.World:

 leftTail.transform.Rotate(10,0,0, Space.World);

If you want to rotate to the angle (10,0,0), use eulerAngles:

 leftTail.transform.eulerAngles = Vector3(10,0,0);

If the leftTail object must be rotated relative to its parent, use localEulerAngles instead:

 leftTail.transform.localEulerAngles = Vector3(10,0,0);

NOTE: eulerAngles is actually transform.rotation converted to Euler angles. You can precisely set eulerAngles to any 3-axes rotation you want, but when reading eulerAngles you may get weird and unexpected XYZ combinations at certain quadrants. Due to this, doing things like reading the current euler angles, modifying and writing it back may produce weird results.

Comment
Add comment · Show 2 · 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 SolaMuhammad · May 21, 2017 at 10:50 PM 0
Share

@aldonaletto Tried all this and it still doesn't work. :( What may be the problem right now ?!

avatar image aldonaletto SolaMuhammad · Jun 14, 2017 at 12:54 AM 0
Share

What means "doesn't work"? Does it rotate to some unexpected angle or it simply doesn't rotate at all?

avatar image
3

Answer by olas72 · Mar 29, 2013 at 11:36 PM

try

leftTail.transform.localRotation = Quaternion.Euler(Vector3(10,0,0));

or

leftTail.transform.rotation = Quaternion.Euler(Vector3(10,0,0));

if you want the turn to be in world space

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
avatar image
0

Answer by robertbu · Mar 29, 2013 at 11:49 PM

You can use Transform.eulerAngles.

 leftTail.transform.eulerAngles = Vector3(10,0,0);

Quaternions use a 4x4 matrix and don't directly map to angles as you think of them. Don't manipulate the individual components of a Quaternion (x,y,z,w) directly unless you understand Quaternions. Note eulerAngles can also be tricky. You want to set all three (x,y,z) at the same time (as you do here with your Vector3). In addition, you cannot expect any specific values from eulerAngles. Any given "physical" rotation has multiple euler angle representations. For example you might set eulerAngles to (180, 0, 0), only to see them change to (0,180,180) instead.

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

14 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

Related Questions

Incrementing Rotation Produces Strange Transform Values 1 Answer

Cannot instantiate rotation on Prefab 1 Answer

Determining Look Rotation As > A Number? 1 Answer

Rotate camera around player 2 Answers

change the rotation 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