1. Lost Twins 2
  2. News
  3. Devlog # 54 - Water mechanics (Simulating Water Flow Between Connected Pieces)

Devlog # 54 - Water mechanics (Simulating Water Flow Between Connected Pieces)

Hi guys! Welcome to today’s devlog. Today we dive into a fascinating mechanic: simulating water flow between two connected pieces. It's always exciting to explore how programming can mimic the behavior of natural phenomena, like water levels rising and falling. In this post, the team will take you through the process of developing a dynamic water flow system that reacts autonomously, adding a realistic touch to the game environment.

To create this effect, the team first set the pivot point of the water prefab to its center bottom. This positioning ensures that when the water is scaled, it appears to be filling up or emptying out realistically. The next step was defining two levels for the water: maximum and minimum. The maximum level represents the current water level for each piece, while the minimum level indicates the empty state.

The flow mechanism comes into play when there are two distinct water pieces: one at its full state (maximum) and the other at its empty state. A variable called `wantedScale` is used to control the water's state. When the `wantedScale` value is 0, the water’s Y scale is interpolated from its maximum value to 0, using Unity’s Update function as shown below:

if (canChangeScale && !isWaterFlowPaused && IsRequiredPieceConnected || (!isPieceDependent && !isWaterFlowPaused))
{
pondVisual.localScale = Vector3.MoveTowards(pondVisual.localScale, wantedScale, MyTime.deltaTime * scalingSpeed);
}


This interpolation effect creates the illusion of the water gradually rising or falling, based on the scaling speed. Once the value reaches 0, the water state transitions to empty, and the other piece begins to fill up with water. The two water pieces operate independently, responding only to their current state.

[previewyoutube][/previewyoutube]

For the flow sequence to begin, the correct piece must be connected to the current piece. If an incorrect piece is connected, the water flow will not initiate, ensuring the mechanic behaves as expected only under the right conditions.

And that’s a wrap on today’s devlog! By using this system, the team was able to replicate the natural behavior of water flow, which adds a layer of immersion to the game world. It's always exciting to bring these mechanics to life, and the team looks forward to refining this feature further.

Stay tuned for more updates, and as always, keep experimenting with dynamic systems in your own projects!

Best regards,
Playdew team

https://store.steampowered.com/app/1752540/Lost_Twins_II/