I’ve searched every corner of the internet to no avail. I’m trying to get a script that can detect if the player camera is underwater, and will take into account waves. Using getvoxels or getcells won’t work because it doesn’t take into account waves and is not accurate.
just an idea, someone will probably come up with a better solution, what if u would create a part and would make a while loop in which u would be setting part.CFrame to CurrentCamera.CFrame? Then u can handle it with touched event or Regions3.
He meant that the way that you can detect whether the player is underwater is by checking if the swimming animation is currently being used and if its used then you can play your sound.
I believe Roblox will need to work more on the water in Roblox Studio anyways.
You can try raycasting at the camera origin forwarding the look vector of the camera:
local Ray = Ray.new(Camera.Position, Camera.CFrame.LookVector.Unit)
local Part, _, FloorMaterial = workspace:FindPartOnRay(Ray)
if FloorMaterial == "MaterialHere" then
end
Top, I tested out what you said and it does not work.
while wait() do
local Ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p, game.Workspace.CurrentCamera.CFrame.LookVector.Unit)
local Part, _, FloorMaterial = workspace:FindPartOnRay(Ray)
if FloorMaterial==Enum.Material.Water then
print('p')
end
end
I heard roblox’s water wave clock is incremented based on the speed or something
So if the speed is 0 when you join the game it’ll be at the starting value. Then you can change the speed to the actual value and take a timestamp and then you have a close estimate on the clock which you can use to determine surface height
Maybe if you raycast from the camera focus to the camera position this would work and using the #4 value from the function:
local Camera = workspace.CurrentCamera
while wait() do
local _, _, _, Material = workspace:FindPartOnRay(Ray.new(Camera.Focus.p, Camera.CFrame.p-Camera.Focus.p))
if Material == Enum.Material.Water then
print("a")
end
end
Hey, this idea might be nuts but just know i’m trying to help. What if you make a part, add a humanoid to it and then constantly position it to where the camera is. And check if that part’s Humanoid.FloorMaterial = water and then do whatever it is you’re doing with ur script. I know…it’s crazy but that’s the way i would approach it. Let me know what you think.
EDIT
ReadVoxels takes in a region3 to match the terrain’s 4x4x4 grid of voxels. It will return a list of materials and occupancies. Materials define if the voxel is in any way populated by terrain. Occupancies describe the voxels geometry and how much that voxel is occupied by the material.
I assume this value can be used for better precision; but it also appears to be constant and probably won’t help with wave size.