A Deep Look at ROBLOX’s Buoyancy and Water Physics


24, 2012

by Kevin He


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.

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.

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.

Buoyancy in action: Boating in ROBLOX.