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
2
Question by Slashik · Aug 18, 2020 at 09:54 AM · rotationtransform.rotationtransform.rotate

Transform.Rotate() is rotating less than given rotation. What's going on?

I am trying to rotate an object a certain amount of angle on each Update(). (it's also jumping with rigidbody.AddForce). Most of the times it works well. But few times, when the object falling from corner of a table because of gravity, the rotation on each Update() is not right. Rotation is less than the expected amount as I check in the next Update() call.

 transform.Rotate(0,0,(360.0f-rotation));
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

4 Replies

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

Answer by Slashik · Sep 01, 2020 at 04:43 PM

Well, finally my problem was solved by setting Angular Drag to 10 for the rigidbody. Hopefully this will help for anyone having the same problem.

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
2

Answer by Captain_Pineapple · Aug 18, 2020 at 10:29 AM

Whenever you do something that is continuous movement (translation or rotation) in the Update function you must take the Frametime into account. multiply your movement by Time.deltaTime and you get a continous rotation of angle/second that acctually is accurate. (especially when changing devices you run your project on)

Comment
Add comment · Show 13 · 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 Slashik · Aug 18, 2020 at 10:39 AM 0
Share

I did that when calculating rotation for each Update() with this code:

 float rotation = rotationspeed * Time.deltaTime;
avatar image Captain_Pineapple Slashik · Aug 18, 2020 at 10:42 AM 0
Share

Okay so in your OP you wrote: " Rotation is less than the expected amount as I check in the next Update() call."


How did you check that?

avatar image Slashik Captain_Pineapple · Aug 18, 2020 at 10:51 AM 0
Share

In Start(): _prevRotation = transform.localEulerAngles.z;

In each Update(): transform.Rotate(0,0,(360.0f-rotation));

_curRotation = transform.localEulerAngles.z;

_difference = $$anonymous$$athf.DeltaAngle(_curRotation, _prevRotation);

_prevRotation = _curRotation;

_difference should be same as previous (360 - rotation). But it isn't. It's less.

Show more comments
avatar image
1

Answer by narasu · Aug 18, 2020 at 10:14 AM

Is the rotation of the object being influenced by the rigidbody physics? And how are you checking the rotation?

Comment
Add comment · Show 3 · 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 Slashik · Aug 18, 2020 at 10:17 AM 0
Share

The rotation itself isn't being affected by rigidbody physics. I am rotating a certain value on each Update(). And I am doing the check with this:

 _curRotation = transform.localEulerAngles.z;
avatar image narasu Slashik · Aug 18, 2020 at 10:32 AM 1
Share

I'm not really sure. If you want your rotation to stay consistent overtime (independent of framerate) you ought to multiply your rotation value by Time.deltaTime. So you could try that out. But it wouldn't account for the value being different each Update loop, I think.

I don't really know more than that, best of luck

avatar image Slashik narasu · Aug 18, 2020 at 10:38 AM 0
Share

Thank you for your responses. :)

avatar image
0

Answer by thegrandmaster97 · Aug 18, 2020 at 12:14 PM

I am struggling with the same problem. even though i use time.deltaTime it somehow seems that almost always it is a bit off. You can not see very much in the beginning(usually it is about 0.3 degrees per rotation) but it still gets really frustrating. There are also times when it can directly jump by a few degrees. Even though it should not be connected to the frame rate it somehow seems that it is.

Here is another post with the same problem and a bit of code:

https://answers.unity.com/questions/1756057/rotate-over-time-does-not-work-properly.html

    public float rotationSpeed = 0.5f;
  IEnumerator LeftRotateCoroutine()
   {
     var degreesPerFrame = 90 / rotationSpeed * Time.deltaTime;
     float time = 0.0f;
    while (rotationSpeed >= time)
    {
        time += Time.deltaTime;
        gameObject.transform.Rotate(0, 0, degreesPerFrame );
        yield return null;
    }

}

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 Captain_Pineapple · Aug 18, 2020 at 01:44 PM 0
Share

please explain to me how the current Time.deltaTime value of each frame will affect the gameObjects rotation.

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

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

Related Questions

Rotating game Object. 2 Answers

How to add limit to object rotation? 1 Answer

Have Head Bone Rotate with Camera 2 Answers

Rotation of object 0 Answers

how can i stop rotating gameobject but slowly 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