1. Lost Twins 2
  2. News
  3. Devlog # 50 - Character physics in water Part 1

Devlog # 50 - Character physics in water Part 1

Hi guys!
Water is finally here! Adding it to our game wasn’t just about making it look cool—it completely transformed how the world and the player interact. From realistic buoyancy to swimming mechanics, creating water physics has been both a technical challenge and a rewarding experience. In this devlog, we’ll take you behind the scenes to show how we implemented character physics in water, tackled unexpected hurdles, and made swimming feel natural and fun. Let’s dive in!

Custom Physics for the Player:
In our game, we’ve built custom physics for all player interactions. While the character uses Unity’s Rigidbody and CapsuleCollider, there’s no gravity by default. Movement is handled manually in the Update() function using boxcasts to determine accurate X and Y positions. With water, we had to extend this custom approach.

Detecting Water Interaction:
To switch between normal platforming and water physics, we added four child transforms to each water area to define its bounds. These allow us to detect when the player enters or exits water. Once in water, the physics shift. A buoyancy force is introduced alongside gravity. For example:

If the player enters from above, they sink initially until buoyancy kicks in, eventually bringing them back up to the surface.

For special water areas (like those suspended in air by magical force fields), the player can enter from any direction, but the buoyancy-gravity interaction still ensures a natural flow.

Swimming Mechanics:
When the player provides input (using arrow keys), the dynamics change: Buoyancy and gravity are temporarily disabled, and the player accelerates in the direction of input. Velocity is clamped to avoid unnatural speeds, creating a deliberate swimming motion.
Additionally, the character’s head rotates to align with the direction of movement, enhancing immersion and giving the swimming motion a natural feel.

[previewyoutube][/previewyoutube]

Handling Physics in FixedUpdate:
Unlike ground movement, which is processed in Update(), water movement is handled in FixedUpdate() for better collision accuracy. Unity’s physics engine takes over here, ensuring the player is stopped by obstacles like walls or floating debris.

However, this introduced an unexpected issue: the camera became jerky since it was still updating in Update(). To fix this, the CameraController now dynamically switches to FixedUpdate() when the player enters water, providing smooth tracking.

[previewyoutube][/previewyoutube]

What’s Next?
This was just the foundation for water physics. In the next devlog, we’ll explore:

Interactions with objects in water, like floating boxes and sinking boulders.
The FX that make water feel alive, from ripples to splashes when the player interacts with it.
Thanks for reading, and as always, feel free to share your thoughts and feedback. Stay tuned for more! 😊

Best regards,
Playdew Team

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