Hi guys :)! I hope you can help me with a rotation problem.
Lets lay down my facts:
I’m modelling a day/night cycle and I didn’t want the sun and the moon just go directly over your head…
If we take a look at the real life, the day night cycle is basically about two rotations. (Just let us assume the sun circles the earth ;))
- The Y-axis. The rotation of this axis determines the time. This is my reference point to the ingame time.
- The Z-Axis. This basically determines the angle of the sun or the moon.
In my project I attached the sun and the moon to an empty gameobject. Lets call it “Time-Pivot”. Sun and moon are facing that Time-Pivot and are on the opposite site of each other.
I also really want to add the feature that I can choose some settings for the cycle to simulate a polarnight or polarday.
For this reason I added 3 custom floats.
This is the maximal angle of the sun and the minimal angle of the moon.
At this angle I defined that the sun is rising/setting. This doesn't has to be 0. Since on the polarday the sun actually passes that point where it would set, but it doesn't, because the risingAngle is > 0.
This is the lowest angle of the sun and the highest angle of the moon. In most cases it should be less then 0, then the sun is under the horizon.
I also added two other settings.
This is the time (in ticks*), when the sun reaches the risingAngle)
This is the time (in ticks), when the sun reaches the rising Angle again.
So I can choose at which time I have the sunset and the sunrise.
*My ingame time is calculated through the rotation of the time-pivot for the Y-axis. So basically, if the Y-rotation of the time-pivot is 180°, it is 12:00.
I have 3600 ticks and one tick is one second.
Now comes the problem:
I managed to do the rotation around the Y-axis with Transform.Rotate(0, 0.1f, 0); So I have 1 tick per second.
This is only the Y-rotation.
I have no idea how to implement the rotation of the Z-axis (the height of the sun).
I thought about something like smoothstep, but I can’t manipulate the rotation, because it is already depending on that Transform.Rotate() thing…
It is about applying two roationspeeds at the same time, but one rotation varys quite a lot.
*I already have functions that can calculate the angle of the Z-axis depending on the time. You may refer it to something like sunAngle(ticks) ← mathematic function. But it returns the angle of the Z-Axis in Degrees. I can calculate the answer but not set it
P.S.: I’m not that experienced yet… If you have a better idea on how to implement the cycle in a good and natural way, you can present your idea instead