- Home /
Controlling the rotation speed of an object?
I have a cube that is spinning at a rapid state and I want it to rotate a lot slower and smoother. Can anyone help me solve this?
This is what I have:
transform.Rotate(Vector3.left * speed * Time.deltaTime, 45);
Answer by Hoeloe · Dec 12, 2013 at 09:46 PM
You're applying the speed in the wrong place. The Rotate function takes two arguments, an axis to rotate around, and an amount to rotate by. The axis is a vector, which just defines a direction (since all it needs to know is the direction of the rotation, which is around the vector). The amount to rotate just instantly rotates the object by that amount, but by repeating the method every frame, you can rotate it continuously.
Note that here, you've applied your speed to the vector component, which, as we determined, is the axis of rotation. Multiplication of a vector with a scalar doesn't change the direction, only the magnitude. Since we also said that the magnitude doesn't matter here, your multiplication by speed * Time.deltaTime
has literally no effect on the rotation. What you actually want to apply this to is the second value, the amount of rotation, since this defines the angle the object rotates every frame.
Thank you, not only did you answered my question but you also helped me understand that line of code.
Thank you very much for being willing to learn rather than just looking for a quick-fix solution. With that attitude, you'll go far.
running this code in update wont make it run at differents speed based on frame rate?
No, that's what multiplying by Time.deltaTime
is for. It adjusts the speed based on framerate to keep it constant.
Answer by Downstream · Dec 12, 2013 at 09:55 PM
You're rotating it at approximately 3214 degrees per second. :) That method of the Rotate-command takes two parameters, axis and angle. You have the two confused.
transform.Rotate(Vector3.left, 45 * Time.deltaTime * speed);
This rotates the cube at a base angular velocity of 45 degrees per second. Remove: 45 * if you want it to rotate at exactly speed per second.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124031im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
The power of the Force 0 Answers
Distribute terrain in zones 3 Answers
How to rotate a GameObject around another object according to the mouse cursor position in C# 0 Answers