- Home /
Rotating Transform Evenly
I have the following FixedUpdate() method on a game object:
void FixedUpdate()
{
transform.Rotate(Vector3.right * Time.deltaTime);
transform.Rotate(Vector3.up * Time.deltaTime);
transform.Rotate(Vector3.forward * Time.deltaTime);
}
However, the x rotation, y rotation, and z rotation are all rotating unevenly. What causes this and how can I fix it?
Additional Information:
Same results for both a 2D sprite and 3D cube.
The order of the Rotate() calls have no effect.
The x rotation rotates substantially slower than the y rotation and z rotation.
The y rotation and z rotation stay relatively the same.
transform.Rotate(Time.deltaTime, Time.deltaTime, Time.deltaTime); yields the same results.
If i rotate it 360 degrees on the x, 360 degrees on the y, and 360 degrees on the z, I want it to actually rotate the 360, and return to its starting position. (All at the same time.)
Still not sure what you want. For example if you do this:
void FixedUpdate()
{
transform.Rotate(Vector3.right * 360.0f);
transform.Rotate(Vector3.up * 360.0f);
transform.Rotate(Vector3.forward * 360.0f);
}
Or this:
transform.Rotate(360.0f, 360.0f, 360.0f);
The cube will be at the start position (within a bit of floating point imprecision).
Note you may also have issues with the difference between local rotation and world rotation. Not sure, but take a look at the optional last parameter to Transform.Rotate(). I think you have a vision in your head of what you want, but we need to have a clear description in order to give you guidance.
that makes it rotate evenly, but now very very slowly...my problem is, if I just rotate by Vector3.one, then why isn't it rotating at the same speed on all axises? (It is more than floating point imprecision). And no, unfortunately the Space did not fix the problem.
@robertbu ive tried just about every possible combination. Even the transform.Rotate(360.0f, 360.0f, 360.0.f); yields the same result of the x rotation happening slower. (Just not as obvious due to the extreme overall slowness of the rotation.) Specifically, what I am trying to do, is rotate a game object around its x axis, y axis, and z axis simultaneously. I want them to start at the same time at a rotation of 0, 0, 0. I want them to end at the same time with a rotation of 90, 90, 90.
Answer by robertbu · Oct 04, 2014 at 06:20 PM
Your code here rotates by 1 degree on the local x, y, and z axis each frame. It is the same as:
transform.Rotate(1.0f, 1.0f, 1.0f);
Your use of Vector3.right/up/forward here is strange since these vectors are directions, and Rotate() takes angles. You need to specify what you want to happen for someone to give you alternate code.
Your answer
Follow this Question
Related Questions
unknown axis of rotation 1 Answer
Setting Up Vector and Still Rotating the Character 1 Answer
Rotate Around Object 2 Answers
How to prevent Z axis rotation ? 0 Answers
Vector3 precision issue? 2 Answers