Water Physics and Buoyancy

A Deep Look at ROBLOX’s Buoyancy and Water Physics

Water Physics and BuoyancyBoats. Waterfalls and geysers. Swimming and diving. Flowing rivers and deep pools. With version 1.0 of ROBLOX’s buoyancy and water physics, carefully crafted and researched by our Physics Team, these things are not only possible, but also realistic. We’re featuring ROBLOX Physics Engineers Kevin He and Tyler Mullen today, as they explain the latest iteration of buoyancy (see the original here) and its implementation in ROBLOX.

Water is more than a texture in ROBLOX. It has its own unique properties and behaviors, all of which integrate into ROBLOX’s existing physics engine. Objects float on water surfaces, bob up and down with pressure changes and sink if they’re too dense. Water flows, pushing objects along its path, with user-defined directions and velocity. Players dive underwater and swim the depths or wade on the surface.

The physics of water are rooted in buoyancy – the tendency of a body to float or to rise when submerged in a fluid, according to the Merriam-Webster dictionary.

[do action=”youtube-iframe” videoid=”aK79zNvNSts”/] Water physics in action: A working water wheel in ROBLOX.

1Buoyancy is a simple concept, but challenging to simulate in a virtual world. We approached the challenge with a few goals in mind. At a high level, we focused on clean architecture so the behavior of objects and characters in water looks and feels like a natural extension of ROBLOX’s existing physics. This included integrating buoyancy into our standard contact pipeline. We actually consider a body of water a special physics object and apply buoyancy to floating objects via the contact (or collision) between them and the water. This way, the collision between water and floater, floater and floater, and floater and sunken objects are all simulated in a unified engine.

Our architecture also unifies all the forces – buoyancy, water viscosity (drag) force, water-flow force, gravity, contact forces and other external forces. The movement of a floating object is a net result of all these forces on a rigid body following Newtonian laws. That’s why you’ll see an underwater collision happening in the same, natural way it does on land.

[do action=”youtube-iframe” videoid=”_SeB7pDUwqw”/] This video demos player control in and out of water, under water and on floating objects.

2We also strived to implement buoyancy and water physics with a high level of detail and accuracy. We came up with a couple solutions based on the type of object we’re simulating.

Cubes and wedges in water

Think about dropping a cube into water. After gravity has submerged it in water, it’s likely going to tumble and re-orient itself as the water’s buoyancy forces it back to the surface. In ROBLOX, we efficiently and elegantly simulate that re-orientation by dividing the voxel cube into eight segments, each of which has its own positional data. By dividing up the force of buoyancy, voxel objects (cubes, wedges and corner wedges) orient themselves properly and respond to changes in force – a character standing on one corner, for example – with realism. We also apply water viscosity force against both linear and rotational velocity to dampen the motion and achieve a good, float-y feel.

Cubes oriented based on density

Spheres and cylinders in water

Now, think about dropping a ball (or sphere) into water. Because the smallest point of the ball enters the water first, it gradually decelerates until the buoyancy force shoots it back up. We don’t need to worry about how the ball re-orients itself, but we do need to know how much of the sphere is below water.

If x is the percentage of the sphere’s height that is under water, then the percentage of the sphere’s volume that is submerged is:

Equation of percentage of sphere's volume submerged

And the buoyancy is weight of object × percentage of volume submerged ÷ SPECIFIC GRAVITY.

Cylinders are the trickiest of all. When cylinders are floating straight up and down, they should act like cubes. When cylinders are floating completely horizontally, they should act more like spheres. The trick, for cylinders, is to blend the two approaches.

If x is the percentage of the horizontal cylinder that is underwater, then the percentage of the cylinder’s volume that is submerged is:

Equation of percentage of cylinder's volume submerged

Again, the buoyancy is weight of object × percentage of volume submerged ÷ SPECIFIC GRAVITY.

This blend of the two approaches allows cylinders to behave realistically in water.

3Our final goal was to allow a wide variety of practical applications through water and buoyancy. You’ve already seen how objects behave in water, but we’ve also developed swimming and diving states that let players jump in and out of water, and swim downward to explore the depths.  Users will be able to construct realistic boats for their games and set up water-based platforming courses. With flowing water, your landscapes and architecture will benefit from waterfalls, geysers, whirlpools and streams.

There’s a lot of new ground – or, should I say, water – to explore.

[do action=”youtube-iframe” videoid=”yiwSIS-mmLg”/] Buoyancy in action: Boating in ROBLOX.

About Kevin He

Technical Director of Physics and Distributed Simulation at ROBLOX. @GongfuTiger on Twitter.

485 thoughts on “A Deep Look at ROBLOX’s Buoyancy and Water Physics

  1. Antonio Donoxo

    Thats So cool…Roblox gets better and better…But not Lego look..Thats sucks

  2. Lordmike2191

    Will there be bricks that go to the very bottom or do they all just float?

    ~Meeper Skeeper~

  3. masterz3992

    Everyone caulm they are still working on this. And I dont realy like the texture of the water and the physics of it but its better then transing a brick and colouring it blue and can collideing it so yea.

  4. luckjes112test

    Okay, Is it compatible with meshes, And does all the scripting still work after it’s in a mesh, So you can easily create huge seas!

  5. Jonathannick

    We have Needed in roblox The water to not thirst,
    If we dont Have any water we Die :P

  6. NickyDJDJDJRoblox

    I need this update Noa, And actuly once they have a good Terrain update. Well, 2nd

  7. Penstubal

    I cannot wait for this to come out! But my question is: does it work without terrain, because terrain lags for me alot?

  8. jamjambam

    nice invention ive been waiting so long for water to match the Terrain,please put this water in as soon as possible thank you

  9. DriftRacer14

    This is cool & all, and believe me I’d like the Water just as much as the next guy, but take UR time in programming it er whatever U have to do. It’d suck if U guys made something we’ve been wanting forever and it instantly breaks ROBLOX as soon as it’s in. BTW when are U guys going to fix the Blue & Orange Wrench button in Studio mode? It lets you put models in but they end up halfway across the map/server and there’s usually a clone of it or something broken in it when it’s inserted.

    1. SirNukesTheBrave

      Seriously, MarioN2, Roblox is nothing like Minecraft.For one, Minecraft does not have perfect circles.

Comments are closed.