I don’t clearly understand fully what you’re trying to do, but I do know that the Sun doesn’t rise at 0 (North), and set at 180 (South). It should rise at more or less 90 degrees (Depending on the day of year), and set at more or less 270 degrees, assuming the day of the year is set at the equinoxes. I assume you’re trying to offset the display degrees, which you can simply do simple addition to the current azimuth value.
And for the Sun height, -90 is directly below horizon (nadir), 0 if its at the horizon, and +90 if directly overhead (zenith). It doesn’t go all the way to 360.
For the Moon, Roblox currently has a fixed Moon phase of a Full Moon, so the best way is to make one separate for the Moon but you will need to mimic the positioning system of the Sun for an artificial BasePart Moon, then apply the Real Sun Path formulae with some modifications. It will be a lot of work given the current Roblox features.
Also nice GUI work you made! Can’t wait to see that astronomy app you’re making!
Hi! It’s a work in progress, but you can already try the whole device here:
At the end of the app list, there should be an app called “Suntimes”, that’s what I’m working on now!
I am currently trying to make an accurate sun path on the front page (here highlighted in red)
The sun icon in the position above is rotated by 0 degrees (sunrise), 90 degrees would be overhead/12pm and 180° would be sunset, do you know how I could achieve this based on variables used in the sungraph script?
You’re free to try out everything I made up to this point, I am still sorting out the chart a bit, you may have seen the Sensors app, that uses some of your formulas along with others (humidity, etc. and EMF, which is fictional and calculated based on near parts with scripts)
A simple 180 degree diagram should be relatively easy so basically lets say you’re living at a high enough latitude where you get about 8 hours of daylight in the winter, and 16 hours in the summer. For every hour that passes, you move the Sun on the diagram about 180 deg / 8 hours = 22.5 deg / hour. And for the summer, you do the same thing: 180 deg / 16 hours = 11.25 deg / hour. So 180 degrees will be the constant, and you’re treating the length of day on the denominator as the variable.
Also looks like you wanna keep 12pm as solar noon, so you will have to shift when you want the diagram changes occur. So in my example, you begin moving the diagram at 8am, and for the summer, you start at 4am.
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?
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
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!
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?
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!
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.
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!
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.
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.