When the animators at Walt Disney Studios first dressed up Rapunzel, the long-haired star of the forthcoming movie Tangled, and had her spin around in front of a mirror, she froze mid-turn, and the folds in her multilayered purple dress turned stiff as shells. The filmmakers had run up against a challenge that has long plagued sartorially inclined animators.

“From very early on, we knew we wanted to get more elaborate clothing than had been done so far in [computer graphics],” says Rasmus Tamstorf, a senior research scientist at Walt Disney Animation Studios Research. “But when a character wearing free-flowing, multiple layers of clothing moves, it can create a lot of contact between the different layers, especially in the way they slide on top of one another. And that can cause problems.”

Rather than scaling back his sartorial ambitions or deploying armies of animators to illustrate complicated scenes by hand—solutions traditionally employed by ambitious animators to get around the challenge—Tamstorf and his team decided it was time to find a new way to solve the problem.

They got in touch with a computer scientist who has made a specialty of studying how materials respond to collisions. Eitan Grinspun of Columbia University’s school of engineering had become fascinated with this area of research in 2002, when he filmed a cowboy hat hitting and bouncing off the floor. He studied the film for hours in slow motion and found the simplest equation that expressed the interaction of variables affecting the hat’s bounce. These included friction, the hat’s “bendiness” (elasticity) and the momentum with which it hit the ground. Then he translated that equation into simple computer code that could be used to predict the movement of any “flexy, bendy material,” including rubber, fabric, even sheets of metal.

But depicting the movement of Rapunzel’s fancy gown posed a larger challenge. With multilayered clothing, a computer must account for potentially thousands of collisions at once. When an animation program becomes overwhelmed with data, it resorts to a “fail-safe,” a backup program that prevents the layers of fabric from creating new collisions. Previous fail-safes continued to move the fabric forward in space but did not allow the layers of material to move relative to one another, creating a rigid, shell-like appearance. After months, Grinspun and Tamstorf’s team came up with a solution. They accepted the need for a collision-stopping fail-safe, but theirs allows the layers of fabric to slide against one another, and it accounts for friction, which affects the speed with which the fabric moves. The result is far more lifelike. Now Grinspun has moved on to a new challenge—developing a program that accurately predicts the movement of hair, which collides in even more complex ways than clothing. He expects his solutions to appear in another animated feature next year.