Im pretty new to programming and have difficulty in math and I want to do a Day and Night Cycle. My structure is like that
SunMoon (Node 3D)
→ Sun (Node 3D)
→ Mesh (Mesh 3d)
–>Directional Light
->Moon(Node 3D)
→ Mesh (Mesh 3d)
–>Directional Light
And the most important thing is this rotation needs to be connected to my Global Time Varibles. Because everything in my game is connected to time. So far so good I made this and thw Sun nor the moon move up or down they just move a few pixels and then back. Idk where I went wrong (Tried to test it first to make it 4 steps)
Seems like you are only setting rotation to 4 fixed positions, maybe using some math would rotate better over time? How are you updating GlobalTime’s hour and minute variable?
var mins: float = Global.hour * 60 + Global.minute
var day_percent: float = mins / (24.0 * 60.0)
rotation_degrees.x = 360 * day_percent
My Node is attached to the SunMoon Node which is the parent node of the Sun and Moon. And by rotation only the parent node the children would come with. Weirldy enough I tried this and only the sun moved.
But if I use
rotation_degrees.y = 360 * day_percent both the sun and moon will orbit the parent node. Aslo when I use .z. But not in the direction I want. But with .x only the sun moves and only tiny bits
SunMoon’s origin is the center of rotation so both sun and moon nodes need to be away from that origin. Then it’s simply a mater of choosing the proper rotation axis, which needs to be perpendicular to “ecliptic” plane, and just rotate a little bit each frame in _process(), or if the cycle is driven by some phase parameter, set the rotation proportional to that parameter.