Hello! I currently have a problem with a lighting script in my gravity-planet game that controls time and latitude to position the sun behind the closest artificial star which is working well but i want it to somehow always be bright even if the ClockTime is night
I tried to adjust the brightness by detecting if the Y position of the camera is higher than the artificial star but it didnt seem to work sadly.
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local cam = workspace.CurrentCamera
Lighting.ClockTime = 6
local atan2 = math.atan2
local sqrt = math.sqrt
local tau = math.pi * 2
local p = Instance.new("Part")
local lights = {}
for _, obj in pairs(workspace:GetDescendants()) do
if obj.Name == "SunFire" then
table.insert(lights, obj.Parent)
obj.Parent.CastShadow = false
end
end
RunService.RenderStepped:Connect(function()
local closest = nil
for _, lightPart in pairs(lights) do
local d = (lightPart.Position - cam.CFrame.Position).Magnitude
if closest == nil or d < closest[2] then
closest = {lightPart, d}
end
end
if closest then
-- Adjust brightness based on distance
closest = closest[1]
p.CFrame = CFrame.new(closest.Position, cam.CFrame.Position)
local dir = (closest.Position - cam.CFrame.Position).unit
local lf = -1
local lat = atan2(dir.Z, sqrt(dir.X^2 + dir.Y^2))
local lon = atan2(dir.Y * lf, dir.X * lf)
local geoLatitude = (lat / tau) * 360 + 23.5
local clockTime = (lon / tau) * 24 - 6
Lighting.GeographicLatitude = geoLatitude
Lighting.ClockTime = clockTime % 24
Lighting.Brightness = 350 / math.sqrt((closest.Position - cam.CFrame.Position).Magnitude)
end
end)
Here is the lighting when your camera is below the y-position of that star in the middle.
Space View:
Now lighting when your camera is above the y-position of said star.
Help would be appreciated, Thanks! ^^