- Home /
Planet Rotation
I have a script that rotates a planet based on the time in hours, but it doesn't work properly. The planet rotates but it doesn't rotate at the proper speed I tested it by making a planet rotate once a minute and timed it and it was well over a minute. rotate2.js
var rotate_time = 5.0;
//time in hours for one full rotation
// ex: saturn = 10.66 hours
function Update () {
transform.Rotate(0, (rotate_time/60/60)*Time.deltaTime, 0, Space.Self);
}
I need the planet to rotate 360 degrees every X number of hours.
In the code I divided by 60 twice so it rotates in degrees a seconds but the input is in hours.
So what should I change to make it work?
Answer by XSSA · Feb 22, 2012 at 07:11 AM
I solved it here it is:
var rotate_time = 5.0;
//time in hours for one full rotation
// ex: saturn = 10.66 hours
function Update () {
transform.Rotate(0, (360/(rotate_time*60*60))*Time.deltaTime, 0, Space.Self);
}
Tested by making it take 0.0166666... for one rotation or one minute and timed it and EUREKA! it took 1 minute to rotate 360 degrees. Oh and for anyone who wants to use this script go straight ahead. Would appreciated some recognition though.
Recognition? I'm pretty sure I wouldn't bother asking for copyright on something as simple as this.
Answer by syclamoth · Feb 21, 2012 at 08:49 AM
It's a simple mathematical error. Instead of dividing by 60 twice, you should really just either add in some brackets to make it more clear what order the operations should run in, or cut to the chase and divide it by 3600 in the first place.