Stylized Water 2
Reading wave data through C#
The package comes with scripting functionality that allows the water surface height and orientation to be read. This in turn can be used for buoyancy calculations. Familiarity with scripting is assumed in order to understand how to use this. If you’re set on making a buoyancy system, understand that it’s potentially a complex task.
Buoyancy will only work for flat water bodies. Rivers or spheres are technically not possible without some complex scripting magic, this starts to delve into a custom physics system.
The wave height and normal can be read at any world position using this static function:
StylizedWater2.Buoyancy.SampleWaves(Vector3 position, Material waterMat, float waterLevel, float rollStrength, bool dynamicMaterial, out Vector3 normal);
The function has a summary, you can view a description for each parameter in your IDE, as well as any overload functions.
This component makes a GameObject and all of its child objects snap to the water surface. It’s a basic non-physics based buoyancy implementation and uses the same API as outlined above.
Because the script sets the orientation of the Transform, modifying all axis, it cannot be rotated manually or through other scripts. Instead, set the rotation of the child objects directly. The position (X/Z value) can be changed freely.
Dynamic Water Physics 2
The DWP2 asset is an advanced buoyancy/hydrodynamics system, that includes a ship controller. An integration is included, that allows them to be used together.
To install the integration, see the Third party integrations section. Note: A minimum of version 2.5.1 is required!
By default, the DWP2 water object will use a
FlatWaterDataProvider component. Remove this, and add the
StylizedWaterDataProvider component. You will have to assign the water material you are using, since this script requires to know what kind of parameters are used for the waves.
For any further details, please refer to the DWP2 manual… (I’m not the author)