Accurate detection of camera underwater

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.

This isn’t impossible, it has been done before.

This is a great example of what I need to achieve. This game takes into account waves, and I don’t know how it works but I want to.

I have had some progress, via help from this thread, but haven’t figured out how to fully implement this equation. A number of problems occur. Firstly it seems I have to make the waterwavespeed 0 for it to work, secondly, it only works in a small area, and only in a specific Y position. I’d like it to work anywhere everywhere with water. Please don’t reply in the comments with compromises, because I’d like it to work fully and accurately.

Alright, so I’ve made a rough map of where it works, and it seems to only work in one direction and only in this small rectangle of space. Additionally, I am unable to make the water move because if I do, it will cease to function

We are making slow but sure progress. I’ll keep you updated on what I come up with next

Also, it only seems to work on 1 stud of 0y.

Any water above or below 0y will not be detected. This is a majour issue since water will and can be anywhere and everywhere in my game.

Here’s a diagramme as to what is happening.
What I want instead, is for all water to be detectable

It seems like even now no one wants to help me tackle this topic. It’s been nine hours and still no reply… :frowning:

You can try checking out this :man_shrugging:

Also from what I know, I dont think its possible to exactly detect the waves from which the water is acted upon. You’d either have to make your own wavy water or deal with the odd glitchiness that comes with it sometimes :pensive:.

The wave effect doesn’t effect anything and is only meant for viewing pleasure meaning it isnt possible (as I know right now though I may be wrong) to detect.

can’t you fire a ray directly downwards from above the camera and hit test it with water?

I tested out the game, and unsurprisingly (seeing as the post was from 2016), didn’t at all take into account waves. Again, I’d highly encourage you (and anyone else posting) to thoroughly read my post

1 Like

I believe they aren’t really trying to detect the waves but moreso replicate the effects as a method to guess where/when the waves are at.

The posts show them trying to get the “math” behind the waves.

sn’t effect anything and is only meant for viewing pleasure meaning it isnt possible (as I know right now though I may be wrong) to detect.

No

I took a look at the thread and it seems that the guy who found out the math said this

It takes approximately 8.4 seconds to complete a full cycle at WaveSpeed 10
Oh, btw this is for when the WaveSize property of Terrain is set to 1

It looks like you just used the equation as is. It will only work on that y level because there is no other position being added to it. Try doing it again but after the equation, add the player’s position or camera position.

1 Like

How will I do that? I’m so stumped. The thread you linked I just found out the guy said it only works with static water. Do I add a wait the speed a water completes a full cycle? If so, then it would not work for that wait! Help me!

Sorry about that, I meant to say that I went to the linked tweet in the thread and got the info there.

I meant How will I do

It looks like you just used the equation as is. It will only work on that y level because there is no other position being added to it. Try doing it again but after the equation, add the player’s position or camera position.

this one? I am so afraid!

I think something very important to note is that place you linked isn’t doing what you think it’s doing.

Try visiting it again and really watching the water. I was perplexed, at first, by how accurate-seeming the underwater sound effect was.

But then I started looking a bit closer and realized… there’s no wave height. There’s no waves at all. What is giving you this “imaginary” effect is that animation of the character. The character itself is bobbing up and down which causes your camera to move in a “wave.”

The creator is simply checking if you’re under the surface of the water or not - as there are no actual waves - by determining if the center of the camera is submerged by about half.

Then what do I do! I’ve been stuck on this conundrum for about a month and a half now and still haven’t even inched close to the solution!

I need a simple and direct answer!

With the image that you have provided, it looks like you just used the equation as is, which happens to be y = 1.8 * sin(2pi/85 * x) * sin(2pi/85 * z)
I was trying to say instead of using just that, you can change the y value based on the player’s position. An example would be:

waveEQ = 1.8 * math.sin(2 * math.pi/85 * x) * math.sin(2 * math.pi/85 * z)
y = waveEQ + camera.Position -- could either be player or camera position depending on the scenario.

Hopefully I was clear in what I initally meant.

Actually, there is. Try running the game and go on the surface of water. Don’t move your camera and let it stay there. The waves actually do move and it’s not (just) bobbing.

I messaged the developer and he said his WaveHeight is 0, as I expected. Your character’s swim animation is making an illusion - as I said.

Jesus, well since that game’s out of the way I still want to achieve this with waterwavesize not 0.