So, it’s pretty self explainatory. The Sun Model is meant to track with the actual sun skybox. It works sometimes but sometimes the ray inside the model just don’t. And it’s a random amount of rays.
Script in StarterPlayerScript:
-- Services --
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
-- Vars --
local Duration = 2400
local totalTime = 24 * 44
local SOLAR_DIST = 500
local sun = workspace:WaitForChild("Sun")
local moon = workspace:WaitForChild("Moon")
local sunDecal = sun:WaitForChild("Sun_Body"):WaitForChild("Decal")
local moonDecal = moon:WaitForChild("Decal")
local function UpdateTime(deltaTime)
totalTime = totalTime % Duration + deltaTime
Lighting.ClockTime = 24 * (totalTime / Duration)
end
local function UpdateSunAndMoon()
local sDir = Lighting:GetSunDirection()
local mDir = Lighting:GetMoonDirection()
local origin = workspace.CurrentCamera.CFrame.Position
sun:PivotTo(CFrame.new(SOLAR_DIST * sDir + origin))
moon:PivotTo(CFrame.new(SOLAR_DIST * mDir + origin))
local cameraPosition = workspace.CurrentCamera.CFrame.Position
local sunDecalParent = sun:FindFirstChild("Sun_Body")
if sunDecalParent then
sunDecalParent.CFrame = CFrame.lookAt(sunDecalParent.Position, cameraPosition)
end
moon.CFrame = CFrame.lookAt(moon.Position, cameraPosition)
end
RunService.Heartbeat:Connect(function(deltaTime)
UpdateTime(deltaTime)
UpdateSunAndMoon()
end)
What it looks like:
Sun Model: