Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
15
Question by Devin Reimer · Dec 14, 2009 at 05:08 AM · rotation

How to Set a Single Axis Rotation of a GameObject?

What is the most efficient way of setting a rotation of a single axis of a GameObject without changing the other values?

Comment
Add comment · Show 1
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 cregox · Jun 04, 2012 at 08:25 PM 0
Share

related: http://answers.unity3d.com/questions/8599/how-do-i-rotate-and-object-around-its-center-in-sc.html

9 Replies

· Add your reply
  • Sort: 
avatar image
27

Answer by Ashkan_gc · Dec 28, 2009 at 06:08 PM

what jaap did can be done by transform.rotate and i think it's not what you want and you want to set the value directly. you can use his code but remove the "rot*" and then the code will be

transform.rotation = Quaternion.Euler(0, 90, 0);

if you want to add some value to any of the x,y,z values simply use

transform.Rotate (0,0,10);

this will add 10 to Z value

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 digopauletti · Apr 28, 2018 at 07:54 PM 1
Share

Works for me. Thanks!!

avatar image AndrueAndersonCS · Apr 19, 2019 at 04:29 PM 2
Share

This answer is clearly incorrect.. it sets all axes of rotation.

avatar image
15

Answer by PatHightree · Dec 14, 2009 at 03:49 PM

I think this is what you're looking for :

// Sets the transforms rotation to rotate 30 degrees around the y-axis
transform.rotation = Quaternion.AngleAxis(30, Vector3.up);
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 kamran-bigdely · Sep 06, 2016 at 09:03 PM 1
Share

I tired it and It resets other angles! That's not what he wants.

avatar image tlutz kamran-bigdely · Sep 08, 2016 at 05:22 PM 4
Share

It has to be multiplied by the original rotation if you do it this way.

 Quaternion originalRot = transform.rotation;    
 transform.rotation = originalRot * Quaternion.AngleAxis(degrees, Vector3.Up);
avatar image
3

Answer by Vishvesh8 · Oct 17, 2018 at 03:49 AM

Try this transform.rotation = Quaternion.Euler(transform.eulerAngle.x, 30, transform.eulerAngle.z);

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 Cephalopod2 · Apr 16, 2020 at 11:55 AM 0
Share

thank you, this was what i needed i think

avatar image tetemcgee · Sep 11, 2021 at 05:12 PM 0
Share

This is exactly what I needed and what whoever asked the question needed as well. THANK YOU

avatar image
2

Answer by Jaap Kreijkamp · Dec 14, 2009 at 06:09 AM

Don't know what you exactly want but maybe this is it:

var rot = transform.rotation;
transform.rotation = rot * Quaternion.Euler(0, 90, 0); // this is 90 degrees around y axis
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 Ashkan_gc · Dec 28, 2009 at 06:00 PM 0
Share

this can be done easily by transform.rotate

avatar image steveh2112 · Feb 07, 2019 at 06:32 AM 0
Share

doesn't this set x and z to zero? what is you want to leave them unchanged?

avatar image
1

Answer by Jessy · Dec 14, 2009 at 05:45 AM

The rotations are stored as quaternions, so you can store the appropriate quaternion and set transform.rotation to that.

Perhaps an explanation of what you are trying to accomplish would help. If you go into "Debug mode" and watch the rotation values change, you can see how just changing one axis's value isn't really more efficient. It only looks that way in "Normal mode".

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
  • 1
  • 2
  • ›

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

LookRotation with constant speed 0 Answers

automatic levelling out airplane when near the ground? 0 Answers

Very basic rotation BUG. transform.up = transform.up sets Y rotation to 0. 1 Answer

Need help with walk on the wall and ceiling 0 Answers

2d Animation, Rotating GameObject bug 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