So, I’m using a day and night cycle and I’m trying to make it so when it’s a certain distance to night the fog and the brightness starts to change. here is how I’m doing it:
if lighting.ClockTime >= NightTime - .5 then
if lighting.Brightness > 0 then
lighting.Brightness -= .025
end
if lighting.FogEnd > 100 then
lighting.FogEnd -= 5
end
if lighting.FogStart > 25 then
lighting.FogStart -= 1
end
end
Ik this is not the most efficient way but idk how else to do it. problem is that this doesn’t work with color of fog. help needed
When I want to change the fog and stuff, I would rather use float numbers to control the intensity of the fog which involves a bit of maths. Simply just taking away and adding the fog intensities imo would be harder to finetune and more complicated.
e.g. A multiplier will be used to increase/decrease the start and end of the Fog.
I wrote a basic script which calculates the multiplier based from the TimeOfDay and then applies the multiplier to the fog. You may need to change the variables to suit your needs.
local Lighting = game.Lighting
local runservice = game:GetService("RunService")
--[[
If ClockTime reaches the end goal, the multiplier will be 1 (turning to night) or 0 (turning to day.)
idk how to explain i'm bad at explaining maths
]]
-- Time Tick
local TimeTick = 0.1
-- Time goals
local NightStartGoal = 17
local NightEndGoal = 20
local DayStartGoal = 4
local DayEndGoal = 6
-- Fog values
local FogStartIntensity_Max ,FogStartIntensity_Min = 1000,100
local FogEndIntensity_Max ,FogEndIntensity_Min = 4500,250
local TimeFloat = 0 -- This is a float number (0-1) which determines the intensity of the fog/brightness/colour
while true do
local dt = runservice.Heartbeat:Wait()
Lighting.ClockTime = Lighting.ClockTime + TimeTick * (1/60)/dt -- Make sure that the tick is not too slow or too fast.
local CurrentTime = Lighting.ClockTime
if Lighting.ClockTime >= NightStartGoal and Lighting.ClockTime <= NightEndGoal then
TimeFloat = 1 - (CurrentTime - NightEndGoal) / (NightStartGoal - NightEndGoal) -- goes from 0 to 1 (night)
elseif Lighting.ClockTime >= DayStartGoal and Lighting.ClockTime <= DayEndGoal then
TimeFloat = (CurrentTime - DayEndGoal) / (DayStartGoal - DayEndGoal) -- goes from 1 to 0 (day)
end
-- Now calculate the fog intensity
local FogStartDiff = FogStartIntensity_Max - FogStartIntensity_Min
local FogEndDiff = FogEndIntensity_Max - FogEndIntensity_Min
Lighting.FogStart = FogStartIntensity_Max - (FogStartDiff * TimeFloat)
Lighting.FogEnd = FogEndIntensity_Max - (FogEndDiff * TimeFloat)
end
Apologies if I didn’t annotate the code, I’m bad at explaining things.
If it is gradually aproaching night, the float variable TimeFloat would increase from 0 to 1 between the variables set by NightStartGoal and NightEndGoal. The oppisite effect is applied when ClockTime is approaching to day. The TimeFloat variable then determines the fog intensities between lines 43 and 47.
Sorry for the late responce, I was just finalising the code.
Oh right, you could’ve just done that as well,
Reguardless, there are lots of solutions out there, My example happens to only be the one that I know of (and personally used before) which is why I thought to include it here.