so i wanna change the atmosphere’s Density and Haze when camera is underwater!
The water is meshpart(not skinned mesh) and im using a script from this video: https://www.youtube.com/watch?v=fn1Rf6SPFYE&t=14s
I’m a builder, illustrator, modeler so im not good at scripting😭 please help!
what i wanna achive:
also i tried to figure it out by searching it in youtube, google, devforum but since there was nothing i wanted, im here asking! again, PLEASE HELPPP
i also tried to scripting it by myself by doing
if CameraUnderwater then
Atmosphere.Density = 0.85
Atmosphere.Haze = 0.5
and it kinda worked(it changed the atmosphere’s settings)
but it was not making the atmosphere to default setting when camera wasnt underwater…
script:
local RunService = game:GetService("RunService")
local Lighting = game:GetService("Lighting")
local Camera = workspace:WaitForChild("Camera")
local Water = workspace:WaitForChild("Water")
local UnderwaterColor = Lighting:WaitForChild("UnderwaterColor")
local UnderwaterBloom = Lighting:WaitForChild("UnderwaterBloom")
local MuffleSound = workspace:WaitForChild("Sound"):WaitForChild("EqualizerSoundEffect")
local UnderwaterSound = workspace:WaitForChild("Underwater Movement 501 (SFX)")
local Atmosphere = Lighting:WaitForChild("Atmosphere")
RunService.Stepped:Connect(function()
local CameraV3 = Water.CFrame:PointToObjectSpace(Camera.CFrame.Position)
local CameraUnderwater = (math.abs(CameraV3.X) <= Water.Size.X / 2)
and (math.abs(CameraV3.Y) <= Water.Size.Y / 2)
and (math.abs(CameraV3.Z) <= Water.Size.Z / 2)
UnderwaterColor.Enabled = CameraUnderwater
UnderwaterBloom.Enabled = CameraUnderwater
MuffleSound.Enabled = CameraUnderwater
UnderwaterSound.Playing = CameraUnderwater
end)
I personally went to the video and checked it out but I personally just made my own script for the water system by using the part in bounds but don’t worry I check the performance and it is low.
I know it looks like a lot but I did some simple disconnecting for it on death so that it won’t leak any memory on the connections. The sound I used is stored in the sound service but you can change the variables if you want.
I just did some simple enabling properties and I tested in game and studio and found no errors on my side.
The script is located in StarterGui
I hope it works!!!
local WorkspaceService = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local lightningService = game:GetService("Lighting")
local SoundService = game:GetService("SoundService")
local Camera = WorkspaceService.CurrentCamera
--[[Global Variables]]--
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local IncludeParts = {
WorkspaceService.WaterPart
}
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {IncludeParts} -- Instance that only include
local watersound = SoundService.UnderWaterSound
local hitbox = Vector3.new() -- Change the hitbox if you feel like it
local RunConnection, HumanoidConnection
--[[Functions]]--
local function UpdateCamera()
local partsincamera = WorkspaceService:GetPartBoundsInBox(Camera.CFrame, hitbox, params)
local isinwater = (#partsincamera > 0)
lightningService.Blur.Enabled = isinwater
lightningService.ColorCorrection.Enabled = isinwater
if isinwater and not watersound.IsPlaying then
watersound:Resume()
elseif not isinwater and watersound.IsPlaying then
watersound:Pause()
end
partsincamera = {} -- Just to reset the table
end
local function OnDeath() -- Just to remove connections on death for memory leaks
HumanoidConnection:Disconnect() RunConnection:Disconnect()
HumanoidConnection = nil RunConnection = nil
lightningService.Blur.Enabled = false lightningService.ColorCorrection.Enabled = false
watersound:Stop()
end
--[[Events / Connections]]--
HumanoidConnection = humanoid.Died:Connect(OnDeath)
RunConnection = RunService.RenderStepped:Connect(UpdateCamera)