There's a way to do sun rotation based on custom days and hours system?
I wrote some simple time code, I showing in a clock the time of game (like 10:00pm), but now I need to rotate the sun using that values, and the sun rise near 5am and the sunset at 7pm (for longer days without changing the time speed).
C#
minute += timeSpeed * Time.deltaTime;
if (minute >= 60)
{
minute = 0f;
hour++;
}
if (hour >= 24)
{
day++;
hour = 0;
}
I was seeing here, I can do something like transform a value in hours to angle, but there's no way to modify just the X rotation of a object, and the transform.Rotate add a value to the current rotation, and does not set it. I want to SET the rotation based on what time is it.
(sorry for my bad english)
Answer by Chrisdbhr · Jan 18, 2017 at 09:58 AM
I did it! Here is my self aswer:
The code in the "clock" remains the same above in the question.
The trick is pretty simple, is in the sun code,
hourAndMinute = hour + (((minute * 100) / 60)/100);
transform.eulerAngles = new Vector3(((hourAndMinute * 360f) / 24f) - 90f, 0, 0);
Here the code is transforming the minutes in a value between 0% and 100%, to do a smooth rotation of the sun. Then, multiplying by 360 (maximum rotation) and divide by "maximum hour" (24 hours), and minus 90 degrees (to correct the sun rotation)
Now, the sun rotation is based in my HOURS and MINUTES!
Holy sh*t take me a long time to do some thing too simple! Sharing with ya guys, hope it helps, again, sorry for bad english.