- Home /
How to modify the rotation speed of an object using Transform.Rotate
So i have taken the sample script from unity documentation for object rotation. I am using JS and the 1st script on the page works well for what i would like to do, except the rotation speed is far too slow for what i would like to do. Unity Page: http://docs.unity3d.com/ScriptReference/Transform.Rotate.html
I tried the 2nd script they offered and played around with changing the variables, but that just changed the direction it rotated in.
Here is the first script that was going too slow. How can i speed up the rotation?
function Update() { // Slowly rotate the object around its X axis at 1 degree/second. transform.Rotate(Vector3.right * Time.deltaTime); // ... at the same time as spinning relative to the global // Y axis at the same speed. transform.Rotate(Vector3.up * Time.deltaTime, Space.World); }
Answer by ian_sorbello · Mar 27, 2015 at 03:27 AM
I don't code javascript - but changing the speed is done by multiplying by some number > 1.0
e.g.
var speed = 4.0;
transform.Rotate(Vector3.right * Time.deltaTime * speed);
Thank you so much. I dont know why i didnt think of that before! Thanks again!
Answer by FirePlantGames · Mar 27, 2015 at 03:31 AM
var speed : float;
function Update()
{
transform.Rotate(Vector3.right * Time.deltaTime * speed);
}
Should suit your needs:) But next time put your code in proper format (Click the picture with the 0's and 1's above your input area)
Hey still thanks for the reply. For some reason the code was all messed up. I even tried to re add it.
Answer by Thlypsis · Mar 27, 2015 at 04:59 PM
Here's how I rotate a planet:
public class Planetside : MonoBehaviour {
public GameObject GOPlanet;
private Planet planet = new Planet();
private float rotationSpeed = -.08f;
void Start () {
planet.GenerateNew();
rotationSpeed = rotationSpeed * 24 / planet.dayLength;
}
void Update () {
GOPlanet.transform.Rotate(new Vector3(0, rotationSpeed, 0));
}
}
Your answer
Follow this Question
Related Questions
Set a relative (custom) speed to a rotation 1 Answer
Transform.rotate gives different result to rotation in inspector 0 Answers
transform.eulerAngles rotating speed (quick question) 1 Answer
transform.Rotate For an Certain Amount of Time 1 Answer
How to rotate object around another object with less than 1 degree. 0 Answers