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
9
Question by Vesuvian · Jan 21, 2012 at 07:41 PM · rotationtransformrotate

Set rotation of a transform

Hi all!

I want to rotate a transform to a specific angle, not add to the existing rotation. Currently, on every frame, I am doing:

transform.Rotate(Vector3.up * rotation);

What I expect is a smooth transition over time as "rotation" changes, however the object is spinning like crazy!

Do I need to use a method to grab the current rotation and then offset by that? Or is there a method that will allow me to directly set the rotation?

Thanks!

Comment
Add comment · Show 4
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 Eric5h5 · Jan 21, 2012 at 08:01 PM 0
Share

You should use Time.deltaTime, since that line of code is not framerate-independent and will vary as the framerate varies.

avatar image Vesuvian · Jan 21, 2012 at 08:40 PM 0
Share

I know what I'm doing with the angle itself, my question is about how to set the absolute rotation of the object, not just adjust the rotation.

avatar image Eric5h5 · Jan 21, 2012 at 08:46 PM 5
Share

Transform.eulerAngles?

avatar image Vesuvian · Jan 21, 2012 at 08:56 PM 0
Share

Thank you! Works perfectly.

2 Replies

· Add your reply
  • Sort: 
avatar image
22

Answer by bbrode · Jan 21, 2012 at 11:37 PM

transform.localEulerAngles = new Vector3(x,y,z);

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
1

Answer by Poisoned-iV · Nov 05, 2016 at 08:58 AM

You can also achieve the same thing as from EulerAngles by:

t.Rotate (Vector3.up, x);

where x is the degrees of rotation you want.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to prevent Z axis rotation ? 1 Answer

Find left joystick Vector2 away from sprite's up direction. 1 Answer

I could not be more lost (rotation script) 0 Answers

How to make a bone rotate facing towards a given Transform? 0 Answers

Quick Shortcuts for Rotation 0 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