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 vogles · May 30, 2012 at 06:17 PM · euleranglesquaternionstransform.rotatearound

Difference between transform.localRotation = Quaternion and transform.RotateAroundLocal

I know there are other questions about the difference between these two things. But I haven't found anything regarding time.

As we all should know, if you call transform.Rotate and give an angle without scaling it using Time.deltaTime, the object rotates at insane speeds. I wanted to be able to clamp the angle of the rotation between 180 and -180. So I decided to add/subtract the rotationRate from a "currentAngle", and then assign that rotation using a Quaternion. To my surprise, I did not need to scale the rotationRate with time to get my desired result. Anyone have any insight to this?

 public class RotateCannon : MonoBehaviour
 {
     public float rotationRate = 30f;
     float currentAngle = 0f;

     void Update()
     {
         if (Input.GetKey(KeyCode.LeftArrow))
             currentAngle -= rotationRate;
         else if (Input.GetKey(KeyCode.RightArrow))
             currentAngle += rotationRate;
         transform.localRotation = Quaternion.Euler(0, 0, currentAngle);
     }
 }
Comment
Add comment · Show 8
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 whydoidoit · May 30, 2012 at 10:17 PM 0
Share

Well that code looks like it would spin the object more than 5 times a second at 60hz - are you sure it isn't spinning so fast you are getting a strobe effect that makes it look like it is working? If you are clamping an angle somewhere that code isn't shown, perhaps something else if affecting it too?

avatar image vogles · Jun 01, 2012 at 08:15 PM 0
Share

The only thing I'm not including is the obligatory using statements. But there is no strobe effect. it is rotating properly without any artifacts or issues. If i switch to something like "translate.RotateAroundLocal" then it does spin so fast it produces a strobing effect. But not through the use of the quaternion. That's why I'm here asking what the difference is.

avatar image whydoidoit · Jun 01, 2012 at 08:47 PM 0
Share

Well I use Quaternions for all my rotations and if I added 1800 to the rotation around the Z axis every second it would be spinning like a mad thing :)

avatar image whydoidoit · Jun 01, 2012 at 08:54 PM 0
Share

Hey I can't post an answer either :(

I have just realised that RotateAroundLocal uses radians and of course Quaternion.Euler uses degrees making quite a big difference in rotation rate :)

avatar image Wolfram · Jun 01, 2012 at 10:12 PM 0
Share

That would be strange, since all Unity functions dealing with Euler angles use degrees, never radians. Only the $$anonymous$$athf functions use radians. But maybe that's why RotateAroundLocal is not (or no longer?) documented.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wolfram · Jun 01, 2012 at 08:51 PM

Hmpf, there is a problem with the site or this question, I can't post an answer (also, my browser deleted my first answer before posting, for the same reason). So here it is as a comment:

Your code cannot produce a "properly" rotating object, unless you modified rotationRate in the Inspector, or there really is a strobing effect (use a different rate to check for that, such as 25).

The difference to RotateAroundLocal is that your code sets the angle absolutely, overwriting/ignoring previous values, while RotateAroundLocal adds the given angle to the transform's rotation each time you call the function.

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 aldonaletto · Jun 01, 2012 at 09:25 PM 1
Share

Converted your comment to an answer - this worked, but UA really has something wrong with this question.

avatar image whydoidoit · Jun 01, 2012 at 09:37 PM 0
Share

I think the other part of this answer is that point about radians and degrees though - that definitely accounts for a speed difference :)

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

7 People are following this question.

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

Related Questions

Keep rotation of not parented item carried by player relative to first person player camera 1 Answer

Rotation Complications + rotation with parents and children? 1 Answer

Yet another turret control thing (5.5.1f1) 2 Answers

Rotation acting weird 1 Answer

Trouble Spawning Bullets with proper 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