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
Nuttela, The touched event doesn’t coagulate with waves, especially terrain.
Tamzy, His post is completely irrelevant and does not help me at all. Detecting the swimming animation does not yield the result I want.
Top, I believe raycasting only works on voxels, is there any way you could show me its accuracy?
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
Unfortunately that is what I explained I did not want in my post because it is inaccurate and does not take into account waves.
Maybe this will help:
https://devforum.roblox.com/t/how-to-get-wave-height-at-a-specific-position/30672/3
That seems needlessly complicated. Also, I don’t think that would take into account the game’s water wave height
That seems needlessly complicated. Also, I don’t think that would take into account the game’s water wave height
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.
Your solution doesn’t work at all. It’s not the problem that it doesn’t function, it just doesn’t function as to detection
A combination of these two should work:
Read terrain voxels
Camera CFrame
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.
I would politely urge you to reread my top post. I explicitly stated I do not want to read terrain voxels, as they are extremely inaccurate and are in a 3d grid of 4 studs per block, and do not take into account waves
Set wave speed to 0 and make a timestamp to base your water clock cycle off of(best guess to roblox’s internal water clock cycle), plug that in to a wave function
+poopnugget142 Frankly, that’s not from a script. Roblox has this built-in as part of their graphics system
+tyridge I still don’t get how this will apply to cameras. So if you’d get the camera’s position and apply the wave function to it, won’t the modified position just wobble around aimlessly? I don’t get how that would help me detect if the camera is underwater or not.
…? Not sure what you’re saying.
If you want to get if the camera is under water, you need to see if it’s below the surface height. Wave function and clock hack detects surface height on a 2 dimensional plane
But what would be the surface height? I want it so that it would be able to detect water in any position, not just a single one. From what I believe you’re saying is that the wave function would work relative to the camera, meaning the modified position would just bob up and down based on the wave function.