- Home /
Sun(light) rotation is not working
Hello, I am trying to set rotation of Sun on the script(game) start. It is based on System.DateTime. All is all right, but rotation is still different(wrong) by my variables.
So here is code:
var sun : Transform;
var dayTime : float;
if(System.DateTime.Now.Hour >= 5 && System.DateTime.Now.Hour <= 19) //15 hours
{
dayTime = ((System.DateTime.Now.Hour-4)*3600+System.DateTime.Now.Minute*60+System.DateTime.Now.Second);
sun.transform.Rotate(dayTime/300, 0, 0);
Debug.Log(dayTime/300);
}
In game rotation of sun is something like X: 327,Y: 180, Z: 180. But i really dont get it, what is wrong with it? But it have to be something like X: 163, Y: 0, Z: 0. If you want more info, just write what you need. Thanks for answers and help.
Edit: Can it be anything like gimbal lock - http://en.wikipedia.org/wiki/Gimbal_lock i really dont know?
Answer by Kiloblargh · Feb 09, 2014 at 06:38 PM
Instead of using transform.Rotate, try setting transform.EulerAngles directly with a single Vector3.
I tried to change it and still not working, same situation :/. When i want to rotate sun over time it's working perfect, but i need to set rotation only time, when game start, and it's not working.
Create 4 rotations called $$anonymous$$orning, Noon, Evening, and $$anonymous$$idnight, deter$$anonymous$$e which two your current dayTime is between, and use Quaternion.Slerp
to interpolate between them.
I need to set rotation of X axis of sun object just only and once time, when game starts(just instantly rotate it), so something like:
transform.rotation = Quaternion.AngleAxis(180, Vector3.left);
for example, but it is still not working :/.
Sorry, that (4 sun position variables, Slerp
between 2) was my most foolproof idea. If you tried that approach and it didn't work, then I just don't know. Your dateTime
math must not be right.