Skip to content
Water Volume

Water Volume

Read this article in 10 minutes

This page outlines the definition of the Water Volume, what it does, how it behaves and how it is used.

What is the Water Volume?

Water Volume Definition: A Water Volume is an area with a certain shape that has surface and underwater effects, and where the character can switch to a swimming state when entering the area. The developers can use this object to achieve swimming effect in the desired area. For example, swimming pools, rivers, lakes and oceans in the scene can be placed in the Water Volume.

The Water Volume exists as a function object in the editor. When you open the editor, in "Gameplay Object" in the left of Asset Library, select "Gameplay Object." In the red box, there is the Water Volume with the asset ID WaterVolume.

Water Volume Usage

How to find the Water Volume?

Find the object in the Water Volume in the asset library - Gameplay Objects list.

image-20240828135949588

Use Water Volume

After we find the Water Volume, we can manually drag it into the scene as needed and modify its properties to achieve the corresponding effect. We can also dynamically generate the Water Volume through code.

The basic properties include the physical properties of the water body and its performance effect. We can change the character's movement in water by adjusting the friction of the water. We can also adjust the surface performance by adjusting the water properties and wave effects.

Dynamic Create Water Volume

image-20240828140114469

You can also hover over the asset you want to view the ID of the asset. You can also right-click to copy the ID of the asset. Then dynamically create the corresponding assets through the asset ID.

Sample script for dynamically generating effects:

ts
// asynchronous spawn, if no asset is found, it will be downloaded and regenerated.
GameObject.asyncSpawn("12683").then((obj) => {
    let pool = obj as WaterVolume;
})
// asynchronous spawn, if no asset is found, it will be downloaded and regenerated.
GameObject.asyncSpawn("12683").then((obj) => {
    let pool = obj as WaterVolume;
})
ts
// Normal spawn generation, cannot be generated without priority loading or preloading assets
let pool = GameObject.spawn("WaterVolume") as WaterVolume;
// Normal spawn generation, cannot be generated without priority loading or preloading assets
let pool = GameObject.spawn("WaterVolume") as WaterVolume;

::: Attention In order to ensure the compatibility of previous versions of water bodies, we have added a new logical object for water bodies, which will use the asset ID of WaterVolume, and the previous logical object for swimming areas will still be SwimmingVolume. In future versions, we will retain the functionality of SwimmingVolume, and previous projects will work fine. :::

Introduction to Swimming Area Properties

Fluid Friction

Function description: The friction of the character in the swimming area affects the acceleration and performance of the character's movement. The braking performance of the character in water is also affected by [Swimming Properties] - [Swimming Deceleration] in the character's properties.

Is Buoyancy

Function description: Adding a buoyancy effect to the Water Volume may make objects with physical simulation properties float in the water body.

Water Attributes

Body Color

Function description: Main colors displayed in the Water Volume

Related Interfaces:

ts
// Find the Water Volume
let water = GameObject.findGameObjectById("21C44BBD") as WaterVolume;
// The main color is set to red.
water.waterColor = LinearColor.red
// Find the Water Volume
let water = GameObject.findGameObjectById("21C44BBD") as WaterVolume;
// The main color is set to red.
water.waterColor = LinearColor.red

Transparency

Function description: Level of transparency in the Water Volume. 0 is completely transparent and 1 is completely opaque.

Related Interfaces:

ts
// Transparency set to 0.6
water.transmittance = 0.6
// Transparency set to 0.6
water.transmittance = 0.6

Water Wave Properties

Wave Intensity

Function description: Water wave intensity on the water surface display effect.

Related Interfaces:

ts
// Set the water wave intensity to 0.3
water.normalFlat = 0.3
// Set the water wave intensity to 0.3
water.normalFlat = 0.3

Wave Angle

Function description: Water wave tilt angle effect

Related Interfaces:

ts
// Set the water wave angle to 0.5
water.flowAngle = 0.5
// Set the water wave angle to 0.5
water.flowAngle = 0.5

Wave Velocity

Function description: Flow speed of water waves.

Related Interfaces:

ts
// Set the speed of the water wave to 20.
water.flowSpeed = 20
// Set the speed of the water wave to 20.
water.flowSpeed = 20

Wave Density

Function description: The overall density of water waves on the water surface.

Related Interfaces:

ts
// Set the water wave density to 500
water.flowTile = 500
// Set the water wave density to 500
water.flowTile = 500

Additional Notes

Control the character's ups and downs.

Related Interfaces:

ts
@Component
export default class Example_Character_SwimDown extends Script {
    // This function is called before the first frame update when the script is instanced
    protected onStart(): void {
        // The following code executes only on the server side
        if(SystemUtil.isServer()) {
            // Generate arch vessels and adapt to swim areas
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(10, 10, 10))});
        }
        // The following code executes only on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's player (self)
            let myPlayer = Player.localPlayer;
            // Get the currently controlled character
            let myCharacter = myPlayer.character;
            // Add a button method: hold down keyboard "1" to float the character
            InputUtil.onKeyPress(Keys.One, () => {
                myCharacter.swimUp(5);
            });
            // Add a button method: Hold down keyboard "2" to dive
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimDown(5);
            });
        }
    }
}
@Component
export default class Example_Character_SwimDown extends Script {
    // This function is called before the first frame update when the script is instanced
    protected onStart(): void {
        // The following code executes only on the server side
        if(SystemUtil.isServer()) {
            // Generate arch vessels and adapt to swim areas
            GameObject.spawn("WaterVolume",{transform: new Transform(new Vector(0, 0, 500), new Rotation(0, 0, 90), new Vector(10, 10, 10))});
        }
        // The following code executes only on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's player (self)
            let myPlayer = Player.localPlayer;
            // Get the currently controlled character
            let myCharacter = myPlayer.character;
            // Add a button method: hold down keyboard "1" to float the character
            InputUtil.onKeyPress(Keys.One, () => {
                myCharacter.swimUp(5);
            });
            // Add a button method: Hold down keyboard "2" to dive
            InputUtil.onKeyPress(Keys.Two, () => {
                myCharacter.swimDown(5);
            });
        }
    }
}