Originally I just made decals of the sun and moon made here and it looked weird due to it glowing, but not only that, I wanted it to be 3d. If anyone knows how to make a 3d sun and moon that’d be a big help, thanks!
-- Get necessary services
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
-- Define the duration of a full day and night cycle in seconds
local Duration = 2400 -- day and night duration (in seconds)
-- Initialize the total time variable
local totalTime = 24 * 44
-- Function to update the time of day
local function Update(deltaTime)
-- Update total time, ensuring it wraps around after reaching the duration
totalTime = totalTime % Duration + deltaTime
-- Set the ClockTime based on the total time elapsed
Lighting.ClockTime = 24 * (totalTime / Duration)
end
-- Connect the Update function to the Heartbeat event to update every frame
RunService.Heartbeat:Connect(Update)
Essentially, I want it to match the speed of the day night cycle too, because a decal sun is either too bright to see it’s design, or if it’s not glowing, it’s a weird white color.
Examples:
I pretty much just want the sun and moon to look like exactly how it was shown in the original post. Thank you!
I left the default 2D moon visible just to show it’s matching the exact position in the sky regardless of ClockTime and GeographicLatitude.
To do this I added two persistent Models to the workspace and then pivot them in a function that could either be bound to RunService.Heartbeat or when the ClockTime property of Lighting changes. This needs to be done in a LocalScript since it’s based on the local CurrentCamera of each client.
local SOLAR_DIST = 512
local sun = workspace:WaitForChild("Sun")
local moon = workspace:WaitForChild("Moon")
--Call this function either every frame or every time the ClockTime changes
local function updateSunAndMoon()
local sDir = Lighting:GetSunDirection()
local mDir = Lighting:GetMoonDirection()
local origin = CFrame.new(workspace.CurrentCamera.CFrame.Position)
sun:PivotTo(origin + SOLAR_DIST * sDir)
moon:PivotTo(origin + SOLAR_DIST * mDir)
end
You may need to change SOLAR_DIST to a higher number depending on how far a player is able to see in your given map. The sun and the moon are models in the workspace like everything else so they will be rendered on top of other parts and models that are farther than SOLAR_DIST away from the camera. Note that the bigger SOLAR_DIST is, the larger you will have to make the models to maintain the same apparent size in the sky.