Coding the Natural Laws of a Cartoon Universe

December 10th, 2014 by Deborah Fike

This is a guest blog post by Jourdan Arenson.

A bone drops in front of Tinker, the cartoon dog. Tinker trots forward. Behind him, he pulls a rope attached to a wagon. The wagon rolls forward, then its wheels jam. Tinker trots in place. The wagon’s handle starts to quiver.

“And then the dog takes off at twenty gazillion miles per hour.”


Tinker goes flying in Contraption Maker
Kevin Ryan is describing a bug in Spotkin’s computer game Contraption Maker. Contraption Maker is the newly released souped-up version of the classic Rube Goldberg puzzle game that Ryan co-created in 1992 called The Incredible Machine.

Like the old version, Contraption Maker challenges players to construct zany machines out of common and not-so-common objects: bowling balls, trampolines, ropes, pulleys, ramps, rockets and vials of nitroglycerin. The laughs start when players turn on their contraption to see how it behaves—or misbehaves.

Ryan, who has programed games for over 30 years, still acts and talks like a precocious teenager. He has a pixie smile, sometimes wears a Crosby, Still and Nash t-shirt, and, in casual conversation, correctly uses the term “order of magnitude.”

He discovered that computers were cool on a 9th grade field trip when he played an early artificial intelligence question and answer program called Guess the Animal. Seven years later, he published his game, Zoo Master, and sold around 100 copies. He went on to write games throughout the dawn of the personal computer, for the Apple II, Commodore 64, and Amiga, on through MS-DOS to Windows.

In his family life, however, Ryan defies the tech-loner stereotype. He is the father of seven children whom he raised and homeschooled with his wife in a Sierra Nevada mountain hamlet, population 634. Even when his kids were little, he always kept the door to his office open. On days with too many interruptions, he had to code at night.

The Incredible Machine

The Incredible Machine – 1992

The Incredible Machine: Out of consistent laws, silly behavior

The birth of The Incredible Machine came in 1992 with Rube Goldberg cartoons. Goldberg is famous for drawings he did during the 1920s depicting crazy convoluted gadgets that executed silly mundane tasks. Ryan wondered how he could turn the cartoons into a game. His solution: “I’ll make the polygons and put the art work around them. I’ll give them a mass and a density. And then I’ll give them Newton’s physics.”

In most games, objects move in a realistic way, but only in a short series of cause and effect. A car takes a turn too quickly and runs off the road. A zombie gets a sledge hammer in the head and flops down. The action continues when the player uses the controller to move the car or character, or the game cuts to an animated scene.

But with The Incredible Machine, Ryan aimed to simulate an indefinite cascade of cause and effect. He wanted to the game world to adhere to consistent physics laws, and he wanted the interplay of cause and effect to be unpredictable, just like in the real word.

To implement the physics, Ryan developed a physics engine—the software component that controls what happens when parts collide, bounce, break up, glide, deflect, and blow up. He created individual parts endowed with physical properties, such as shape outline, mass, density, and movable joints.

parts interacting

Different parts have their own shape, mass, and density.

When he assembled the parts into the first test contraptions, he was surprised by the unpredictably goofy action. “I tried to get as close as I could to the real values and I let it go. What came out was this huge emergent behavior.”

“Emergent behavior” is the scientific term to describe how simple individual parts interact in a structure that performs actions greater than the sum of the parts.  For example, when car makers arrange wheels, pistons, a gas pedal, and many other parts into just right structure, they get an automobile—a structure that is self-moving. Contraption behavior is usually sillier, but the principle is the same: small interactions between individual parts add up to produce the novel behavior of the whole.

When a player starts a contraption, the physics engine receives information about all the parts initial position: vector path, mass, surface friction, bounciness and other properties. As gravity begins, the engine applies Newton’s laws to figure out how all the parts react in the first moment. The game simulates the first reaction on the screen. This reaction now becomes the initial conditions for the next action-reaction cycle. Players watch the contraption’s full behavior emerge as the physics engine repeats the action-reaction simulation 240 times every second.

Since real-world physics can be boring, Ryan spiced up his game physics with whimsical forces. He included anti-gravity pads and super balls that gain height and speed with each bounce. “I cheated with the physics a bit,” he says, “because sometimes going beyond reality is fun.”

In addition to physics, he subjected the living creatures that populate contraptions—cats, dogs, alligators, mice and little men—to a simple biological law: Eat and avoid being eaten.

Contraption Maker has an assorted cast of characters.

Contraption Maker has an assorted cast of characters.

“When animals come within range,” Ryan says, “they query each other: ‘What do I think of you?’ ” If the other animal is a predator, the answer is: “You are scared of me, and this is how much you are scared of me.” The potential prey then evaluates if it is more scared of the predator—or more attracted to some nearby food.  From this simple artificial intelligence emerges the characters’ cat-and-mouse antics.

In the end, The Incredible Machine was a fun game that turned out educational. It was written about in academic papers with titles like Critical Factors in the Design of Playful Learning Environments. And it was played by students in thousands of classrooms around the world.

A player contraption that uses lasers to sort different sized balls

A player contraption that uses lasers to sort different sized balls

Contraption Maker: Powerful new world faces new problems

When Ryan coded Contraption Maker twenty years later, he tapped the greater computing power of modern devices. He increased the artificial intelligence of characters and added more sophisticated physical properties to the physics engine. But the variety of modern devices introduced a new problem: Identical contraptions sometimes behaved differently when run on different machines. As a result, players could not enjoy collaborating across devices.

The problem stems from the fact that devices use math chips that calculate in different ways. For example, an Intel 80-bit chip returns a number with many more places after the decimal than an AMD 64-bit chip. Both results are correct, but the results from the 64-bit chip are rounded to fewer decimal places.

For most computer programs, the slight difference doesn’t matter. But because Contraption Maker’s behavior emerges from a long cascade of cause and effect, tiny variations can eventually cause identical contraptions to behave differently. “Even a small 0.000001 difference,” says Ryan, “can cause huge differences in how a physics simulation runs because of ‘the butterfly effect.’ ”

The butterfly effect is a theoretical example illustrating how minor differences in the initial conditions of a system can lead to large differences in its future state. In the example, the air displaced by a butterfly flapping its wings in one part of the world combines with myriad other atmospheric conditions to produce a hurricane one month later in another part of the world.

butterfly effect contraption

A tiny change in a complicated contraption can have huge consequences.

The butterfly effect made contraption behavior inconsistent. When a contraption was run on an 80-bit chip, the mouse would get the cheese. But when the same contraption was run on an 64-bit chip, the cat might get the mouse.

To allow players to share contraptions across all devices, Ryan concluded he could not rely on existing math libraries or chips’ built-in functions. So he wrote his own sine, cosine, square root and other trigonometric routines. “That was an enormous undertaking,” says Keith Johnston, Engineering Director on the Contraption Maker team. “There aren’t many people on the planet who could do that in the amount of time that Kevin did it, and have it perform as fast as we needed it to.”

Unfortunately, bugs still pop up—like when a dog sky-rockets off screen. Somehow, Ryan has to fix these bugs without messing with the laws of his universe. “It is really tough to tune physics,” he says. “You can’t just fix a specific situation. The behavior is coming out of Newton’s formulas.”

Usually, Ryan finds a solution by fine-tuning a part’s properties. In the case of the flying dog: “His feet were too sticky, so they were accumulating a tremendous amount of force on the rope.” The fix was to reduce the friction between the dog’s feet and the ground. This prevented the physics engine from building up the catapulting force.

Other times, the emergent behavior is too funny to fix. Once Ryan discovered that two alligators placed nose to nose trigger each other in a snapping frenzy. He wasn’t sure how to fix it, then decided: “That’s not a bug, it’s a feature.”

Jourdan Arenson bio: Jourdan Arenson is a science and technology journalist who works in Eugene, Oregon, the same town where Spotkin is located.

facebooktwitterrssyoutube

Comments are closed.

Contraption Maker


Want to Stay Updated?

Sign up and we'll let you know about future updates

Shennanigans Free Zone! We will never spam you or sell your email




Follow Us on Twitter