Sun Rotation to Hour?
Hey guys!,
What would you do if u wanted to get a 24h float or int from a transform.Rotation.x ???
I got my sun rotating but need to transpose that actual rotation on the x, to an Hour variable...
Simple math i know? cant figure it out.
Rotation / 360f / 24h ?
Ty!
Answer by ZefanS · Dec 17, 2015 at 01:59 AM
As long as the sun is only rotating about a single axis (the x axis for instance) this will work. There are 24 hours in a day and 360 degrees in a circle. Assuming that midnight is when the sun is pointing straight up (away from the world) and noon is when it is pointing straight down (towards the world), we have that 0 hours corresponds to 0 degrees (0 being straight up) and 12 hours corresponds to 180 degrees. The math itself is then quite simple; you were almost there:
Hour = rotation/360 * 24
Or in Unityscript:
hour = transform.eulerAngles.x / 360.0f * 24.0f;
Just make sure to check that 0 degrees does in fact mean that the sun is pointing straight up. If not, you'll need to adjust the calculation.
Your answer
Follow this Question
Related Questions
Camera self rotation script problem 1 Answer
Player rotation always resets. 0 Answers
Why won't my model rotate up on X axis? 1 Answer
Problems with limiting angles 1 Answer