Atmosphere effect from player Hight

So I am making a platformer game inspired by getting over it.
in that game, the higher the player gets the more the background changes.
it goes from bright and sunny to a sunset to dark space.
I want to recreate this effect, but I have no idea what I’m doing…
Any help?

you can set the clock time property of lighting and change the atmosphere density.
Atmosphere | Documentation - Roblox Creator Hub
Lighting | Documentation - Roblox Creator Hub
for example as a player goes up have a checkpoint that changes atmosphere density and clocktime.

``````script.parent.touched:connect(function()
game.lighting.clocktime = 20
game.lighting.atmosphere.density = 0.7
end)
-- sorry i dont have script editor open right now. so it might have some incorrect names
``````

edit: you should use @Prototrode solution its way better

1 Like

Instead of using the player’s height, it might be better to use the camera’s height instead. Once you get the Y coordinate, you use the linear interpolation formula to calculate what atmospheric setting corresponds to that specific height.

Linear interpolation is important because you need to set a lower and upper bound for the measured height level and the effect it will have on the atmosphere. First, you calculate the “alpha” of the height:

``````local alpha = (currentHeight - minHeight) / (maxHeight - minHeight)
``````

The alpha is a number that interpolates between the minimum and maximum values. You can think of it as the reverse of the `:Lerp()` function for vectors, CFrames, and Color3. If the alpha is 0, the player is at the minimum height, and if it’s 1 then it’s at the maximum height. But it’s possible for the player to exceed the bounds, so you need to clamp the alpha value.

``````local alpha = math.clamp((currentHeight - minHeight) / (maxHeight - minHeight), 0, 1)
``````

After finding the alpha, you repeat everything in reverse, this time using the alpha to find your atmospheric setting, i.e. the time of day.

``````local clockTime = minTime + (maxTime - minTime) * alpha
``````

You can test all of this by substituting in the min/max values. For this example, let’s say when alpha=0 the time is 12:00, and when alpha=1 it should be 20:00. And alpha is 0 when the camera’s Y position is 0, and it is 1 when the Y position is 100.

``````local minHeight: number = 0
local maxHeight: number = 100
local minTime: number = 12
local maxTime: number = 20

--run this in a loop so it updates
while true do
local cameraHeight: number = workspace.CurrentCamera.CFrame.Y
local alpha: number = math.clamp((cameraHeight - minHeight) / (maxHeight - minHeight), 0, 1)
local clockTime: number = minTime + (maxTime - minTime) * alpha
game.Lighting.ClockTime = clockTime
You can do the same thing to other settings like `Atmosphere.Density`, `Atmosphere.Offset`, `Lighting.Brightness`, etc. using this same process.