Water Wave Velocities in HDRP Water System

I am working on realistic water physics simulations and want them to work well with Unity’s HDRP water system. For an object to float on the water’s surface, I need more information than just the current height of the waves. I need the velocity of the waves as well. At the very least I need the rate of change of the surface height at a given position. Does anyone know how I might access this information, or whether there is scope for including this in the water system?

I have implemented my own water system and can differentiate the height function wrt time to get the vertical velocity of the waves. I then use that velocity to compute a drag force acting on the floating object, meaning that a rising wave will actively push the object upwards regardless of buoyancy effects, and a falling wave will pull the object down. This makes objects follow the waves much more reliably, including objects which are neutrally buoyant.

The current issue I’m getting when working with Unity’s water system is that the object only rises and falls due to the buoyant force, there is no pressure force pushing the object up and down as the body of water moves. This leads to undesirable effects such as the water wave falling too far below the object or completely submerging the object when the waves are too large for buoyancy and gravity to keep up.

Interesting question, I don’t think there’s anything like that exposed through the API. I wonder if comparing the height of the last sampled position(s) to current one(s) would be adequate, if the object isn’t moving very quickly in x/z. Or alternately, if you compute the depth of the object you could use the rate of change of that?

Thank you for the suggestion!

Unfortunately, the objects are free to move in all directions so any kind of filtering to determine the water’s rate of change is going to be difficult to do. I believe the water system is using some kind of FFT model, it shouldn’t be too difficult to include the rates as well as heights, but I don’t know how to go about requesting this from the team?

You can select an area here and click “Submit an idea”:
Product roadmaps | Unity

Based on some comments in other threads, I think the water system is considered feature-complete and not getting much active development, and this is kind of a niche request, so I wouldn’t expect it to get picked up anytime soon

In addition to “height” you can also retrieve the normal and the current direction in the WaterSearchResult struct.

Based on the current water height and the maximum wave height (on your component) you should be able to compute a proportional force to push floating objects based on that !

Thanks for taking the time to respond!

I am using the height and normal to produce the buoyancy force but that’s more of a static force and doesn’t properly account for the motion of the waves. I don’t want to include a maximum wave height for objects as that would stop being physical and could lead to problems where other forces and interactions are involved.

If you only have the buoyant force then the wave needs to submerge more of the object before it can be pushed upwards with the wave. Similarly, when the wave moves down, the only force remaining to bring the object down is gravity, but you can have waves in the water system which move down faster than an object falling under gravity could keep up with. This leads to a lag between the wave and the object, and when the waves are large and moving quickly you will often see the object being completely submerged (even if it is quite buoyant) or left hanging in the air as the waves fall from underneath it.

This isn’t what happens to objects in the water. If you have ever been floating in the ocean or in a wave pool with large waves you might know the feeling of the waves carrying you up and down, that is different to the buoyant force. The waves don’t have to submerge you and increase the buoyant force to cause you to stay at the surface, you are actually pushed by a pressure force due to the motion of the water. That is the effect that is missing and why I want the rates out of the water system.

Sorry for the essay.. I’m working hard on a lot of water physics simulation tools at the moment and this is causing a hard limit on what I can achieve in Unity. If there is a repository for the water system I could look at I would be happy to do some testing and submit a pull request with this feature!

No problem, thanks for the details. I completely agree with what you are saying.
I just wanted to point out some obvious data that could be used to approximate some kind of “force” but it remains indeed a large approximation and we don’t have data like motion vectors for the waves sadly so I don’t see how to make it more accurate with the data that we have currently !

I’d love for it to be a feature in the future! My current workaround is to use my own water system but I am not a graphics developer so that comes at the cost of all the gorgeous visuals that your water system provides.

Sorry to pester you on this but I’ve been working on some boat mechanics so I’m interested in the topic. Are you using Rigidbody physics, and if so is the Drag parameter set to something above zero? I don’t really see objects getting submerged more than they should be using a buoyant force based on displaced water volume, and a simple “buoyant drag” force based on vertical velocity^2 * wetted surface area. It’s not exactly accurate since as you point out, the velocity for calculating a drag force should be relative to the local wave vertical speed, but it sticks pretty well. At some point I’ll switch to either roughly sampling wave speed from height at current x/z - height at last x/z or using rate of change of wetted surface area as a proxy, or using Rigidbody velocity to predict the next x/z and sample height there to compare to the next update. But having even a small positive Drag factor on your Rigidbody will cause buoyancy to lag badly IMO.

I’m using rigid bodies for the force application but I am calculating all the forces myself. There’s pressure drag, viscous drag, wave making drag, as well as buoyancy. We then also have the above surface aerodynamics forces and any actuation forces like propeller models, jets etc. The application is more broad than just boats, we’re looking at submersibles, surface vessels and even aircraft with floats. Hence the need for physics models that can accommodate everything and not wanting to cut corners with approximations.

Buoyancy and damping have their place but they just aren’t enough for what I am working on and since using my own water system with the wave velocity information I can’t go back. If I have some time during the week I’ll make a demo video comparing the two and link it for reference.

Have you checked the water sample? it contains an example of a floating object