I’m trying to create clouds that change color depending on the time of day so it looks realistic.
Unrealistic:
Realistic:
I’ve read through all the devforum posts and cannot find anything about this topic.
I’m trying to create clouds that change color depending on the time of day so it looks realistic.
I’ve read through all the devforum posts and cannot find anything about this topic.
The simplest way would be to tie the clock time directly to the RGB color of the clouds:
local lighting = game:GetService("Lighting")
local clouds = workspace.Terrain.Clouds
local function Update()
local hour = lighting.ClockTime
-- will be be 12 at midnight, 0 at noon, and 12 again at 24:00
local howLowIsTheSun = math.abs(hour - 12)
-- will be 0 at midnight, 1 at noon
local brightness = (12 - howLowIsTheSun) / 12
-- will be black at midnight, white at noon
clouds.Color = Color3.new(brightness, brightness, brightness)
end
lighting:GetPropertyChangedSignal("ClockTime"):Connect(Update)
Update()
A more in depth way would involve changing the equation to be more interesting, possibly to use a ColorSequence | Roblox Creator Documentation or something similar. That would let you do stuff like make the clouds pink at sunset, etc.
Here’s that fancier option, for fun!
local lighting = game:GetService("Lighting")
local clouds = workspace.Terrain.Clouds
-- ColorSequence stuff stolen directly from https://developer.roblox.com/en-us/api-reference/datatype/ColorSequence
-- first and last colors should probably match!
local cloudColors = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.new(0, 0, 0)), -- black at midnight
ColorSequenceKeypoint.new(0.25, Color3.new(0, 0, 1)), -- blue at 6:00 AM
ColorSequenceKeypoint.new(0.5, Color3.new(1, 1, 1)), -- white at noon
ColorSequenceKeypoint.new(0.75, Color3.new(1, 0, 0)), -- red at 6:00 PM
ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0)) -- black at midnight again
}
function evalCS(cs, time)
-- If we are at 0 or 1, return the first or last value respectively
if time == 0 then return cs.Keypoints[1].Value end
if time == 1 then return cs.Keypoints[#cs.Keypoints].Value end
-- Step through each sequential pair of keypoints and see if alpha
-- lies between the points' time values.
for i = 1, #cs.Keypoints - 1 do
local this = cs.Keypoints[i]
local next = cs.Keypoints[i + 1]
if time >= this.Time and time < next.Time then
-- Calculate how far alpha lies between the points
local alpha = (time - this.Time) / (next.Time - this.Time)
-- Evaluate the real value between the points using alpha
return Color3.new(
(next.Value.R - this.Value.R) * alpha + this.Value.R,
(next.Value.G - this.Value.G) * alpha + this.Value.G,
(next.Value.B - this.Value.B) * alpha + this.Value.B
)
end
end
end
local function Update()
clouds.Color = evalCS(cloudColors, lighting.ClockTime / 24)
end
lighting:GetPropertyChangedSignal("ClockTime"):Connect(Update)
Update()