Under Water Effect

Hey Guys so I’m working on a One Piece Inspired game and I decided that I’ll give away some of the scripts that I’ve made, here’s the Under Water Effect, I will also explain it below…
https://gyazo.com/5c1e44854ce749572b991d231afd580b


local cam = workspace.CurrentCamera

while true do
	wait()
	if cam.CFrame.Y < -0.3 then
		local Info = TweenInfo.new(0.3)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=0.3})
		Tween:Play()
		local Info2 = TweenInfo.new(0.3)
		local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=10})
		Tween2:Play()
	elseif cam.CFrame.Y > -0.3 then
		local Info = TweenInfo.new(0.3)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=1})
		Tween:Play()
		local Info2 = TweenInfo.new(0.3)
		local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=0})
		Tween2:Play()
	end
end

This is what you need to put in the ScreenGui, basically create a ScreenGui then inside of that ScreenGui add a Frame, make sure to set the size of it to (1,0,1,0) this is in case you want your game to be cross platform, furthermore make the frame a blue-ish tent and make the transparency of it to 0
image

In Lighting insert a BlurEffect, then rename it whatever you want, but if you are new to scripting then you should just change it to ‘UnderWaterBlur’ Like I have in my game so that the script works first try, change the Size of the blur to 0 in the properties section
image

This bit of the code basically detects if the camera is below -0.3 studs on the Y axes, you can change that number based on the water level, it will take a bit of testing but trust the process, furthermore after it detects if the camera is below Y -0.3 it tweens the Frame’s Transparency and also it tweens the Blur Size.


if cam.CFrame.Y < -0.3 then
		local Info = TweenInfo.new(0.3)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=0.3})
		Tween:Play()
		local Info2 = TweenInfo.new(0.3)
		local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=10})
		Tween2:Play()

In this bit of code, the code detects if the camera is above the Y axes of -0.3, and if it is then it tweens the Blur Size and the Frame Transparency, it basically reverts the effects.


elseif cam.CFrame.Y > -0.3 then
		local Info = TweenInfo.new(0.3)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=1})
		Tween:Play()
		local Info2 = TweenInfo.new(0.3)
		local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=0})
		Tween2:Play()
	end

I hope you guys found this helpful! :slight_smile:

17 Likes

A better solution would be to check what the humanoid is standing on and to fire a ray from the camera to check that the camera is underwater, then you can apply whatever effects you want.

It’s still a cool effect nonetheless, personally I like trying to muffle any audio being played to emulate that underwater sound feel.

I was thinking of adding a under water sound effect too, but it will take a while to find a fitable sound for it

You can emulate this effect with pre-existing sounds with SoundEffects (i.e: the ReverbSoundEffect instance).

alot of games have water on different levels so if you want to have a part called water level then u can change the code to this

local cam = workspace.CurrentCamera
local watelevel = workspace.Water.Position.Y
while true do
	wait()
	if cam.CFrame.Y < watelevel  then
		local Info = TweenInfo.new(0.3)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=0.3})
		Tween:Play()
		local Info2 = TweenInfo.new(0.3)
		local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=10})
		Tween2:Play()
	elseif cam.CFrame.Y > watelevel  then
		local Info = TweenInfo.new(0.3)
		local Tween = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=1})
		Tween:Play()
		local Info2 = TweenInfo.new(0.3)
		local Tween2 = game:GetService("TweenService"):Create(game.Lighting.UnderWaterBlur,Info2,{Size=0})
		Tween2:Play()
	end
end
5 Likes