Issue with my water detection

Another solution potentially would be to have a way to detect when a player is in terrain water without raycasts (which I am unaware on how to do). And then if they are inside water we find the top and bottom by raycasting in increments of five. E.g I’ll raycast from 5 studs up in the air to find the surface and if I dont find the surface then I’ll increase it by 5 again and repeat that until the surface is found. Could also make it 10 stud increments since I doubt I’d have 2 bodies of water 10 studs above or below another.

Well right now you also have to manually write out all the coordinates to make sure you’re in water (unless you do it differently, but I don’t know how else you would check if the player is in water with your current system without X, and Z position checks + the Y raycast). I’d find that more annoying to be honest.

Also I misunderstood a bit, I thought you abandoned the default Roblox water altogether (for stylistic reasons for example) which would make my solution less annoying

1 Like

I dont use the X and Z coordinates at all. I just check if the player is within the Y coordinates of the water.

Is there a way to tell if a player is inside of terrain water? If there is then I can do my previous mentioned solution of incremental raycasts to avoid the problem.

I may be forced to just do the incremental raycasting without another way to detect if a player is in water. I wanted to detect if they are in the water before doing all the raycasts just to be better on performance but oh well.

Could you run something on the client that detects if the player is in the part every frame by using workspace:GetPartsInParts()?

1 Like

I am using terrain water so I cant use getpartsinpart.

You can take the bounds of your character, and see what percentage is in the bounds of water. If it’s less than 50, no swimming. You can use terrain water, and overlay an invisible collision part.

1 Like

The issue is how do we even get the bounds and detect water?

Region3 | Documentation - Roblox Creator Hub This may do

1 Like

Region3 is deprecated according to staff but I literally cannot find any other ways to detect if ur inside water which is kinda frustrating. Idk why they’d deprecate it if its the only way to detect terrain water.

If you only check the Y coordinate then you won’t be able to have any sorf of elevation in your game, are you sure that’s okay?
For example a hill with water inside of it is impossible:

or just a ramp going down will also be impossible:

You will also have to make sure that no terrain goes too low or too high because then you might get falsely flagged as in water.

Sounds like much more of a headache to me rather than just adding a big part to each lake/water

Is there a way to tell if a player is inside of terrain water?

I couldn’t find anything on it but there could be.
Apparently workspace.Terrain.Touched only fires when you touch water but that seems like a very inconsistent solution

1 Like

I don’t see how a hill with water doesnt work. Also it doesnt just check terrain it makes sure its actually water.

The blue dot is a player and the red lines are the raycasts.
image
Its not just raycasting once it raycasts in a constant loop and updates the Y position just for that issue. If I used parts I’d have to use ramps or rotated parts just to detect that ramp on the side.

Edit: to clarify terrain cant block the raycast either. I have a custom function that will raycast beyond any terrain obstructing the water. Not that my game uses any terrain anyways the only terrain used in my game is water.

Couldnt you just use Roblox’ swim, but only as in the HumanoidState? That way you could read the state, and if it’s swim then you’re in water.

1 Like

I have to disable this state for my own custom swimming so no I cant use it to detect if a player is in water unfortunately.

You can do a voxel scan at the player’s position. That’ll return occupancy.

1 Like

that uses deprecated region3s. I’m probably just gonna have to incrementally raycast constantly without doing a check to make sure they are in water first. I only wanted to do that just so I’d only be raycasting when I had to.

Region3 isn’t deprecated. Region3 | Documentation - Roblox Creator Hub and besides deprecated doesn’t mean you can’t use it

1 Like

Can’t Humanoid.Swimming work?

1 Like

As I mentioned previously I disable the humanoid swimming state so this would not work. I use my own custom swimming which is why I want to detect water in the first place.

Instead, couldn’t you create a hitbox wherever water is, and check when those parts are touched?