shown in other instead.
Water body enables physical simulation of liquids of different density and viscous behavior. It also models the appropriate buoyant force on submerged objects and wave dynamics as two-way interaction is calculated. Water simulation is visually pleasant and fast enough, so it can be used within a game environment; however, if the mesh is big and dense, it can become quite costly.
Water body can be assigned to the following types of objects:
Grid Simulation Model
The water body is modeled as a two-dimensional grid with point particles positioned in the vertices of the mesh. The particle movement is restricted to two directions: it can be lifted upwards or dragged downwards. In the case of changing its position, the particle acquires a velocity that affects the neighboring particles and thus describes the grid of water body at each physics time step. Thus, the waves are generated when physical bodies get in contact with water or a particle is directly assigned new velocity.
Liquidity defines the viscosity of water (or any other liquid): it determines how readily it splashes and affects wave formation. It multiplies the speed with which water particles pass velocity vectors to the neighboring ones.
- The higher the value, the more viscous the water is and the smaller are the waves risen by the objects (e.g. syrup).
- Low values provide higher surface waves (e.g. tap water)
.Be careful not to set too high or too low values, because it may lead to unstable simulation and blowing up of the water. To regain stability, try to tweak Interaction
Density of the water determines the buoyancy of objects according to Archimedes' principle. Based on the volume of the submerged part of the shape and its mass, buoyancy force is applied to its center of mass and pushes the object upwards, whereto the mean normal of the grid covered by submerged shape points.
- By the minimum value of 0, the objects will not float in the water, but rather fall through it without any resistance.
- Higher values increase the buoyant force. If set too high, the immersed objects start to be pushed out in the air.
Physical Behavior of Objects in Water
Two-way dynamic interaction provides both physically and visually convincing simulation of the waves from the physical bodies as they disturb the fluid. Imagine the moving boat that forms a wake behind it, or the character that ripples the water as the he wades through (see the picture above).
Interaction with Objects
A physical object submerged into the water (or any other liquid) has its own velocity vector. On the other hand, all the water particles that are covered by this physical body or surround it, have their own integrated velocity vector, which approximates the state of water. Interaction value is a coefficient that determines how much the object's velocity influences the velocities of water particles and thus generate waves.
- By the minimum value of 0, an object produces no disturbances on the water surface.
- Higher values make the disturbances of water surface more intense and the waves from moving objects become higher.
Too high values may blow the water up, as the law of conservation of energy does not constrain the system! Try decreasing damping values to regain stability.
Linear Damping and Angular Damping
Objects getting into the water are expected to slow down, as resistance of the water is higher than the drag in the air. Damping values work the other way around compared to Interaction coefficient:
Linear damping defines how much linear velocity of the submerged object is decreased over time when influenced by velocities of surrounding water particles. And similarly, angular damping defines the gradual decrease in the object's rotation. Both linear and angular damping forces are accumulated before being applied.
- By the minimum value of 0, objects movement is not hindered by the water. As a result, there are no waves in the water.
- Higher values make the damping of linear or angular velocities more intense, and objects slow down faster as they get into the water. The waves from the objects in this case become more pronounced, as the energy of the system increases.
The water may blow up in case the values are be very high. Try decreasing interaction value to regain stability.
Emission of Particles
It is possible to create an additional visual effect of small droplets, splashes or bubbles on the water when objects fall into it. To enable this effect perform the following steps:
- Create a particle system effect by clicking Create -> Effect -> Particle system in the main menu of the UnigineEditor.
- Go to the Particles tab in the Parameters window.
- In the Dynamic section choose a spark emitter to spawn particles by selecting Emitter -> Spark.
- Make particle system a child of the water mesh object.
An example illustrating this effect can be found here.
The following parameters relating to water boundaries make it possible to create different types of basins in the game environment. These parameters provide flexibility in setting up physical behavior of water for big natural lakes and small pools.
Depth determines the size of waves: high waves are formed in deep waters (e.g. a sea), while only a slight ripple is generated in shallow waters (e.g. a pool):
- With the minimum value of 0, the objects raise no waves in the water.
- Higher values result in higher waves generated by moving objects.
Intersection with the Ground
Intersection of water with the underlying terrain can be necessary, for example, to estimate the actual depth of the water basin. To enable ground intersection perform the following steps:
- Make water mesh or dynamic mesh object a child node of the terrain or static mesh
- Check the Intersection box in the Body section on the Physics tab of the Parameters window.
Intersection is implemented in the following way: the rays are traced downwards from the water mesh surface, as far as the depth distance. If a ray intersects the parent node, the obtained depth is used in calculations; otherwise the preset depth value is used.
Intersection is also traced upward to check if the water is under terrain and there is no need to render it.
Absorption is an option that creates either an effect of a limited basin or, on the contrary, of an open water surface that does not have marked boundaries.
- If Absorption is enabled, the waves are dispersed along the mesh perimeter. In this case the water level at mesh edges will gradually fall down to zero level.
- If disabled, the backwash from the wall is simulated: the wave when reaching the brink of the water is reflected and returns in the reversed direction.
Distance of Simulation
To improve performance and avoid the excessive load, water simulation can be limited to the specified distance. When the water body is beyond this limit, physical calculations are not performed, though objects preserve their buoyancy.
- If set to infinity (inf), there is no distant-dependent optimization for water. This value is set by default.
Assigning a Water Body
To assign a water body to an object via UnigineEditor perform the following steps:
- Open the World Hierarchy window
- Select a water mesh or a dynamic mesh object to assign a water body to. Make sure that object's mesh meets requirements!
- Go to the Physics tab in the Parameters window and assign a physical body to the selected object by selecting Body -> Water.
- Set body's name and change other parameters if necessary.