Gamasutra: The Art & Business of Making Gamesspacer
Scaling a Physics Engine to Millions of Players
View All     RSS
October 30, 2014
arrowPress Releases
October 30, 2014
PR Newswire
View All

If you enjoy reading this site, you might also want to check out these UBM Tech sites:

Scaling a Physics Engine to Millions of Players

July 12, 2012 Article Start Page 1 of 3 Next

[An ex-Blizzard physics and networking lead for online game Roblox shares the secrets of how the Lego-like building game simulates rigid bodies for millions of players at a time -- without losing either performance or fun.]

Roblox is built on a comprehensive physics engine, and our millions of users are constantly generating content that pushes it to the limits of its capabilities. To enable our users' unrestrained creativity and cope with their passion for ever-larger and increasingly complex simulations, we've committed ourselves to a regimen of physics-engine optimization.

In Roblox, we simulate all rigid-body physics because our users create games on the foundation of bricks, blocks, wedges, spheres and cylinders. These elements behave in game as they would in the real world, which eases the learning curve, makes it possible for users to create games in almost any genre, and adds a layer of discoverability -- all contributors to the 250 million hours of gameplay our users logged in 2011.

We should note that complex physics simulation doesn't make a game good and, in many cases, would be a waste of resources. Instead, the complexity of a physics engine should parallel the gameplay requirements.

Roblox's Physics, In Context

Roblox is near the extreme end of the physics-complexity spectrum in gaming. On the other end are MMORPGs -- from EverQuest to World of Warcraft -- which employ basic collision detection to keep players confined to playable areas.

First person shooters, such as Halo, and action RPGs, such as Diablo III, take collision-detection a step further with contact force and limited collision shapes (e.g., capsule) to generate a collision response. They also put characters into a "passive" ragdoll state, sending them tumbling after death or flying after an explosion, and use "decorative" ragdoll -- moving hair, for example -- to add dynamic visuals.

Sports are where physics simulations start to get interesting and complex. In addition to everything seen in MMORPGs and action games, sports games, such as Fight Night Round 4 and FIFA 12, introduce "active" ragdoll, where motors actually power the joints of the fighters and players. This helps achieve smooth, life-like motion and animation. Without their motors, fighters' and players' limbs would hang lifelessly and they'd collapse to the ground.

Finally, there's Roblox, where full physics simulation is enabled by default, disabled as the exception. All physical objects -- terrain excluded -- are simulated. Our engine features:

  • Collision-detection with contact force and a rich set of collision shapes, including box, sphere, cylinder, wedge, convex hull and more
  • Full rigid-body dynamics, integrating all relevant forces (gravity, contact force, friction, joint/spring force, buoyancy, viscosity and kinematic body force) in one pipeline
  • Physics-based character animation, "passive" and "active" ragdolls, balance controllers for standing, running, jumping, falling and swimming
  • Mechanical vehicles and boats, built on a rich set of joint types, including kinematic, hinge, weld, rope, prismatic, revolute, motorized and more
  • Buoyancy and advanced water physics

These simulations must also perform in a networked, multiplayer environment.

From Discrete to Aggregated Physics

Give someone a set of building blocks and they're probably going to use as many as possible to create something massive. Roblox is no exception, but simulating every single part of a skyscraper or a Titanic-sized ship as an individual -- or "discrete" -- rigid body is prohibitively expensive for network and CPU/GPU resources.

We are smart about simulating massive structures and vehicles. When a skyscraper is anchored to the ground and immobile, we treat it as a single entity, attached to the background environment. No dynamic motion is simulated for the discrete bricks and only collision detection is performed between the skyscraper and other moving parts or mechanisms. Our engine compresses the entire skyscraper into a static, "featherweight" part that consumes little memory. "Featherweighting" helps a Roblox world scale to thousands of complex buildings with minimal cost.

For a Titanic-sized ship sailing in water, the entire ship must run in our rigid-body dynamics engine in order to simulate a realistic, floating effect, the interaction with water and collisions with other floating objects. Simulating each of the ship's thousands of parts as individual rigid bodies would be prohibitively expensive, so Roblox simulates such high-volume, welded rigid bodies as a more efficient "Assembly" to manage resources during physics simulations.

Roblox dynamically identifies pairs of objects that do not move, relative to one another, during a frame of motion. It groups such objects together, creating an Assembly. Even a Titanic-sized ship with a thousand parts welded together is simulated as a single rigid body. This is the kind of efficiency we need to scale our physics simulation to millions of parts.

In this scenario, two parts form an Assembly, as they do not move, relative to one another, during a frame of motion.

Assemblies are not a silver bullet; their implementation presents a unique set of challenges. In a dynamic environment with constant movement, collisions, explosions, and human interactions, Assemblies are formed, fragmented, and merged all the time. Here are some common examples:

  • Parts glued together can break with enough separation force
  • Bodies originally separated can be welded together at run time when the "inlet" of a part's surface touches the "outlet" of a part's surface
  • Humanoid characters will be torn apart when killed, even due to a sword strike, because the joints are broken
  • Users can write LUA scripts to dynamically insert or remove joints between two parts and cause the break-up or merge of Assemblies

Our engine has to synchronize a consistent composition of Assemblies in real time, between clients and servers, while these changes are happening. We select the same root bodies for Assemblies and generate them in the same order across the client and server boundary to achieve smooth networked motion.

Article Start Page 1 of 3 Next

Related Jobs

Square Enix Co., Ltd.
Square Enix Co., Ltd. — Tokyo, Japan

Blizzard Entertainment
Blizzard Entertainment — San Francisco, California, United States

iOS Engineer, San Francisco
DeNA — San Francisco, California, United States

Software Engineer, Game Server
DeNA — San Francisco, California, United States

Full Stack Engineer, Games


Jeremy Alessi
profile image
Fantastic article! Thank you so much for sharing!

Federico D'Angelo
profile image
Great article! I have only one question, how do you deal and detect hacked clients or cheaters?

Kevin He
profile image
It is indeed a growing concern for tightening up client security. In general you want clients to simulate at high frequency of all the physics details and let server to validate the digest at much lower rate. For example a trivial validation is to check player move speed. Based on the specific gameplay you can design a bunch of validates that are not so heavy to run at servers.

Kevin Fishburne
profile image
Nice job. Complex client/server stuff can be a bitch, eh? What's funny (or sad?) are the YouTube video comments. It appears as though some gamers have absolutely no idea what programming a game involves. Even a Tetris clone is no walk in the park, but distributed realistic physics on an MMO scale requires godlike skill and determination. Keep up the good work.

Also, keep in mind (as Federico mentioned) that if the client is sending any data to the server it needs to be sanity checked. My project simply limits client-to-server data to gamepad input to avoid cheating. The server receives raw gamepad data and updates clients and the world state accordingly. Just pretend the client will be open source from day one and you'll be in the right mindset.

Kevin He
profile image
That's right! We are hosting 5.4 million user generated games instead of one large game world at MMO scale. Also a lot of our games are social, collaborative and community managed. So scalability outweighs security to some extent. Still we need evolve our system to defend against simple hacks.

Ole Berg Leren
profile image
This made me wish I was awake during physics class. My underdeveloped and sleep-deprived mind (thank you, World of Warcraft) just couldn't understand both particle and wave models of light at the same time :| Maybe I should give it another shot.

Following that train of thought, maybe Roblox could be used to introduce students to physics? Has there been any interest in using it for educational purposes?

Kevin He
profile image
Right on! ROBLOX is designed to be both an entertainment platform and an education platform. In the recent RGC (ROBLOX Gaming Conference) a lot of parents gave us great feedback about how ROBLOX helped their kids to beef up their Physics and Programming skills. One of the players showed me a Physics Education Clan he created and a bunch of physics based puzzles you have to solve in order to be admitted to the clan. Another kid told me that he decided to pursue an engineering/computer degree after watching our boats and buoyancy demo.

donald shiner
profile image
region-bounded collision detection. yep, i wrote an algo for that and submitted it to my very favorite programmers' website, it's a cool visual demo of NSpace, a region-bounded radial collision detection system developed by yours truly, codeguy. also, it's a c++ emitter compiled with a publicly-available compiler, so it runs very nicely. everything is rendered and collision-checked using rebound equations utilizing COR, mass, vectorized motion, etc. this should allay any fears about not "being qualified to run that machinery."