- Home /
Constant Rotation to an Object
How would I make an object constantly rotate in a single direction? This particular time being in the Z axis? For all eternity? Undisturbed forever?
Answer by pravin gate · Mar 17, 2011 at 09:53 AM
var degreesPerSecond : float = 50.0;
function Update() { transform.Rotate(Vector3.up degreesPerSecond Time.deltaTime, Space.Self); transform.Rotate(Vector3.left* degreesPerSecond * Time.deltaTime,Space.Self);
rigidbody.isKinematic = true;
}
you can use this one also to rotate constant speed as u want.
Because you put:
rigidbody.isKinematic = true;
You made me realize I had to instead directly rotate the rigidbody, and not do so through transform.rotation. 10 years later and you helped me!
Answer by Unamine · Mar 17, 2011 at 10:59 AM
There is a script ready in case of Lerpz which can be downloaded directly from the official site. Is the tutorial 3dplatform
Answer by RuneShiStorm · May 15, 2017 at 05:14 AM
I cant make it work :/ I just want a COG rotiation in the background. Do I have to turn this asset into a Prefab or can I just drop it on the scene and add some sort of script to make it rotate? (2D plaformer)
I'm pretty new on this, but maybe this could work:
public float rotateSpeed; //set it in the inspector
void Update () {
rotate();
}
void rotate() {
transform.rotate(Vector3.right, rotateSpeed * Time.deltaTime, Space.World);
}
You may need to change .right to one of the other static variables found here: https://docs.unity3d.com/ScriptReference/Vector3.html
Hope this helps.
Answer by MatteoGodzilla · Jan 05, 2018 at 01:22 PM
you can use this:
void Start () {
z = 0.5f; //velocity
}
void Update () {
game.transform.Rotate(new Vector3(0,0,z)); //applying rotation
}
the transform.Rotate
function is applied to the existing rotation,not to the 0 of that axis. If the object is rotated 25 degrees and you apply to the rotation 2 degrees , the result will be tilted 25+2=27 degrees
Your answer
Follow this Question
Related Questions
Change characters direction using camera view 0 Answers
How to make the npc face the player. 2 Answers
rotate smooth toward vector defined by controls 1 Answer
Rotating character based on joystick angle, at an angle 0 Answers
velocity direction 1 Answer