Changing ClockTime based on player's position

I’m working on a game feature so that the further away from earth you get, the darker it gets.
However, I have no idea how I would even start making this. Does anyone have any ideas?

There are multiple ways to achieve this. I will show you one of the more simple ways.

You would have a script check the player’s position often, and compare it to the center of Earth’s position.
You can subtract both of those Vector3’s and use Magnitude to get the distance count (in studs).

So for example:

local playerDistance = (HumanoidRootPart.Position - EarthCenter.Position).magnitude

then you can use that number value to determine what darkness level you should apply to whatever you are using to display darkness, like Lighting Brightness/Colors to Fog. I dont suggest using ClockTime as that mainly just controls the sun and moon position. What you would want to do is make the global lighting darker, which you can do by lowering the Brightness and making Ambient and OutdoorAmbient darker.

I will give you an example for that:

local playerDistance = (HumanoidRootPart.Position - EarthCenter.Position).magnitude
local distanceUntilMostDark = 1000 -- change this
local darknessLevel = playerDistance / distanceUntilMostDark
darknessLevel = math.clamp(darknessLevel, 0, 1) -- so it doesn't go into negative or above 1.

local darknessColor = Color3.new(0.7,0.7,0.7):Lerp(Color3.new(0.1,0.1,0.1), darknessLevel)

local Lighting = game:GetService("Lighting")
Lighting.Brightness = 1 - darknessLevel
Lighting.Ambient = darknessColor
Lighting.OutdoorAmbient = darknessColor
2 Likes