Real Sun Path | Realistic Sun Movement and Longer/Shorter Days!

Thank you! I was able to get it working with this function

function calculate_sundial_rotation(daylength, t)
			-- Convert time t to be within the range of the day (0 to daylength)
			local rotation;
			t = t % daylength

			-- Calculate sundial rotation
			if t < daylength / 2 then
				rotation = (t / (daylength / 2)) * 90  -- Rotates from 0 to 90 degrees
			else
				rotation = 90 + ((t - daylength / 2) / (daylength / 2)) * 90  -- Rotates from 90 to 180 degrees
			end

			return rotation
		end

Do you plan on adding moon stuff, and phases to your script? :slight_smile:

EDIT:
This seems to actually be more precise, however, there’s still some offset between actual sunset and 180°.

local function calculateRotationAngle(t, dayLength)
	t %= 24
	local anglePerUnitTime = 180 / dayLength
	local rotationAngle = (t - sunriseTime) * anglePerUnitTime
	return rotationAngle
end
2 Likes

Moon phases would be far fetched, especially I tend to work this script alongside 3D Atmosphere, which involves a mesh that blocks FogEnds to create an atmosphere. Hope your script works now, sorry for the late reply but yeah. If Roblox has a feature where parts can appear behind another part, I will definitely add realistic Moon phases too!

1 Like

Hello
I am doing a small game, where you will be able to fly in space
I have an invisible Part which represents the Sun and I would like to position the Sun Skybox texture “behind” the Sun Part when the player looks at the Sun Part (i.e. at the place on the skybox where the direction vector between the player and the Sun Part “hits” the skybox).
I care only about the X and Z position. I would like the “height” of the Sun texture to remain more or less same all the time (around 15-16 o’clock)
So I wonder how can I set (and update) the correct Sun texture position in game using the Geographical Latitude setting?

Thanks in advance

1 Like

I don’t clearly know what exactly you’re doing but to my understanding, if you’re going to make a space game, I would highly recommend you using my 3D Atmosphere script 3D Atmosphere - Roblox where it already does what you are describing. The Sun’s texture is already customizable, and with accurate apparent diameter and refraction effects.

Hey amazing work man… everything is just so well prepared and thought off… Just one quick question, I’m unable to figure out how to make a real time script which works with this system, unlike the one it already has which simply just plays a cycle that isn’t synced with the real world.
Any help would be appreciated!

1 Like

Basically the ClockTime value inside this script is based on local solar time, with 12pm referring to when the Sun crosses the meridian on an average.

By default, the display time, which is on the game clock may be ahead or behind the ClockTime value (local solar time), depending of where you are on the ideal timezone, plus any DST offsets.

If you wanna sync with the actual Sun, you will have get the current time of the day in real life, and subtract it by the Sun offset, which can be found in the game clock, which this script comes with.

I may implement something like that for future updates but so far you will have to do a bit of math. The best part is that you will be working with decimal hours though.

Thank you! I’ll see what I can do with my kinda basic scripting skills lol

That’s pretty cool. The atmosphere module could change a lot of visuals in some games.

Heyy tysm again! I was able to make the cycle with a very simple script! The results are awesome and incredibly accurate!

Why did you use GuiMain over ScreenGui?

(it’s deprecated)

Alright it’s me again lol… I have an issue with the clouds… I wanted to add them to the game, however, with the 3d environment feature seems like they are set in the background and can’t be seen… What solutions can I try?

Unfortunately, the Roblox clouds aren’t compatible with 3D Atmosphere, hence why I had to use an improvised cloud system for the game I used 3D Atmosphere in. One way of improvising clouds is to stack decals and use a cloud texture. Then offset them on the XZ plane in random directions. This article has a great solution to the cloud problem: Volumetric Clouds: Phase 2!

I see… I’ll have to give it a try I guess… It’s a shame we cannot customise Clouds in any way
Thank you so much anyway!

Edit: I have thought about a way better alternative to this problem rather than using different clouds or not using the 3D atmosphere, here’s my idea:
Instead of simulating the upper atmosphere with a mesh, we could stick to Roblox’s built in sky box to replicate the same effect. This could be done by changing the sky box texture according to the Atmosphere color/texture value.
I believe this could be possible to implement and I think I could be able to figure it out (no promises lol) but I’ll need to actually get to know how’s the transition in the atmosphere’s colour to replicate the same effect on a decal, and that might be something I’ll need your help with (if you are willing to).
Thanks in advance!

This seems really nice!

I made a season system on my game that changes throughout the year and wanted to have the length of the day change with the seasons. Lets say I was a bit disappointed in Roblox’s system. I’ll take a look at this script for sure

Hi, sorry to bump this but I just discovered it, and it is exactly what I was looking for. I just had one issue. I noticed the sun/moon jittering or briefly going the opposite direction, especially at midday and midnight. I see that this is a known bug when refraction is enabled at the poles but I seem to be getting the same issue regardless of what the refraction or geographic latitude are set to. Don’t know if this is a bug or something I’m doing wrong but I would appreciate some pointers to how to fix it.

Edit: Adjusting the day of year to follow the time of day fixed some of the jittering but not all of it.

1 Like

Its a known issue, where if you’re at the poles, refraction will mess up during the midnight Sun. It can be fixed through more mathematical calculations involving a pivot, which Roblox’s Sun pivots on by default, which will be of unnecessary hassle, which refraction can easily be disabled when at the poles. Unless you’re making a planetarium game, players won’t even care about 1-2 minute deviations in the Sun’s position. Also for the Moon, unfortunately Roblox fixes the Moon at the opposite side of the Sun, which you’ll have to create your own Moon system, using this script as a foundation.

1 Like

how would i make it to only show the (fake) sun? im trying to get a fake sun to replace the actual one since the actual one dissapears from 18:00 till 6:00 and it looks weird

1 Like

I put this into my game and it does a really good job. I have a suggestion though. Would it be possible to add a BoolValue into the script that is set to true between sunset and sunrise? My use case is for external lighting (e.g. Streetlights) that only should be on during the hours of darkness. Originally the lights simply use hardcoded time values checking Lighting.TimeOfDay but with this script that is no longer accurate due to how the script alters these values to change the hours of daylight/darkness.

1 Like

Just use my 3D Atmosphere script! Very easy to set up

You don’t really need to have a bool to check if its actually day or night. The script basically does its calculations to fine tune the lighting’s ClockTime and GeographicLatitude “coordinates”. You still use the same system as before. Check if lighting’s ClockTime is between 6pm to 6am. Remember that 6pm on the lighting’s ClockTime might translate to 9pm in the summer or 4pm in the winter on the provided clock. Therefore no need to change anything really!