How to detect if the player camera is in water?

Im trying to figure out how whenever the roblox player camera is in terrain water they add that tint how is that done exactly because you can detect if the player touches terrain or is swimming but from what i can tell you cant really do the same with the local camera. If anyone knows how it is done or has a suggestion please tell me.

2 Likes

You can cast a short ray from the center of the camera and see if it hits any terrain water with https://www.robloxdev.com/api-reference/function/Workspace/FindPartOnRay

You can do this by creating a Region3 around the camera (with an offset) and then use Terrain.ReadVoxels to check the material; repeating every step

8 Likes

ill try it

1 Like

A post was merged into an existing topic: Necrobumping

To anyone who may read this post.

If you have a flat world and water level is the same all over the map and no underwater caves you can simply get the cameras CFrame to determine if it is under water.

You will need to get the camera.CFrame.Y, you can determine the sea level by printing the CFrame.Y and moving the camera so that half the screen is underwater, take note of that number, in your script you will use that number to determine if the camera is below sea level.

For example if camera.CFrame.Y < 10 then – we can safely say the camera is below sea level.

12 Likes