- Home /
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));
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.
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)
I did that when calculating rotation for each Update() with this code:
float rotation = rotationspeed * Time.deltaTime;
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?
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.
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?
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;
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
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;
}
}
please explain to me how the current Time.deltaTime
value of each frame will affect the gameObjects rotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613005921im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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