Problem with my underwater effect!

  1. What do you want to achieve?
    II want the camera effect to stop between two waves !

  2. What is the issue?
    the underwater camera effect is displayed between two waves !

  3. What solutions have you tried so far?
    My code currently deduces the max height where the water will go however it thinks the camera is underwater when it is simply between two waves !

local RunService = game:GetService("RunService")

	local cameraPos = workspace.CurrentCamera.CFrame.Position +,2-workspace.Terrain.WaterWaveSize,0)
	local x, y, z = cameraPos.X, cameraPos.Y, cameraPos.Z

	local min, max = + 0.01, y + 0.01, z + 0.01), - 0.01, y - 0.01, z - 0.01)
	local region =, min)
	region = region:ExpandToGrid(4)

	if region then
		local material = workspace.Terrain:ReadVoxels(region, 4)
		if material[1][1][1] == Enum.Material.Water then
			game.Lighting.Blur.Size = 10
			game.Lighting.ColorCorrection.TintColor =, 0.803922, 1)
			game.Lighting.Blur.Size = 0
			game.Lighting.ColorCorrection.TintColor =, 1, 1)

Underwater Effects - Resources / Community Resources - DevForum | Roblox

1 Like

Your solution have the same problem, but thanks for your answer ! :wink:

My camera isn’t underwater but the effect go on :

local Size = 2
local min = workspace.CurrentCamera.CFrame.Position - (Size *, 1, 1))
local max = workspace.CurrentCamera.CFrame.Position + (Size *, 1, 1))

change the size

1 Like

I understand but when the waves are high your effect is displayed between the two waves try! :sweat_smile:

The waves come next to / over the camera, I don’t see the problem

send a video

maybe try adding a bit of height to the region pos

1 Like

I just did it but basically roblox thinks we are underwater when you are between two waves, try to write your material variable, put yourself between two waves, it will show that the camera is well under water ! :expressionless:

Theres a community resource of a formula to approximate roblox height

1 Like

I’m between two waves ! :sweat_smile:

I don’t understand what you mean :


I mean roblox wave height try search for it

1 Like

I have already managed this on my own but what happens is that roblox believes that have is under water while have is between two waves! :sweat_smile:

Thats not accurute enough try this Sampling Terrain Water Height at Any Position

1 Like

In the worst case test my code if you want to see my problem, increase the size of the waves and you will see that between two waves the effect is displayed ! :grinning:

I see your problem, The fact that roblox wave are sort of like noise YOu cant just use a number value to sort of approximate the height, Thats why i say you should try use this Sampling Terrain Water Height at Any Position and sample it at the player position

1 Like

Yes I understand and I looked but it won’t tell me what I want, in reality I want to get a variable that tells me when I’m between two waves that I’m not underwater and my calculation works you can try ! :wink:
Have a good day, I need to go ! :yum:
Thank you so much for your help ! :grinning:

It does not work … :disappointed_relieved:
but thanks for the help! :wink:

If we summarize my code is able to know the height where the player’s camera could be under water, that is to say the maximum height of the waves except that when the waves have passed the effect continues because the camera still believes to be under water ! :disappointed_relieved::sweat_smile:

Do the code for you???
Also @tin_nim Has already told you what to do :smile:

1 Like