Trying to make a simple little detail that makes the screen darker when you go deeper underwater, my math is broken today, so if any one could help me out that’d be appreciated.
If you still don’t understand, in real life, if you go really deep underwater, it’s most likely that it’ll be dark, because the light from the sun are not able to reach that point.
local param = OverlapParams.new()
param.FilterType = Enum.RaycastFilterType.Whitelist
param.FilterDescendantsInstances = {workspace.Ocean} --customize this, for example: {workspace.Ocean}
local cam = workspace.CurrentCamera
local hitbox = Vector3.new()
local color1 = Color3.fromRGB(141, 148, 212) --// Surface tint color (SHALLOWEST)
local color2 = Color3.fromRGB(45, 47, 66) --// Darkest tint color (DEEPEST)
game:GetService('RunService').RenderStepped:Connect(function()
local parts = workspace:GetPartBoundsInBox(cam.CFrame, hitbox, param)
if #parts > 0 then
game.SoundService.AmbientReverb = Enum.ReverbType.UnderWater
game.Lighting.OceanBlur.Enabled = true
game.Lighting.OceanColor.Enabled = true
local newColor = color1:Lerp(color2, (math.abs(workspace.OceanBottom.Position.Y - cam.CFrame.Position.Y)/488.15464782714844))
print(newColor)
game.Lighting.OceanColor.TintColor = newColor
else
game.SoundService.AmbientReverb = Enum.ReverbType.NoReverb
game.Lighting.OceanBlur.Enabled = false
game.Lighting.OceanColor.Enabled = false
end
end)
For me, the screen darkens during the shallow waters area, and goes bright when it reaches the deep area.