Game Development Reference
In-Depth Information
never be moved—and the physics engine can rely on certain optimizations based on the
fact that static bodies never collide with each other.
Dynamic bodies, on the other hand, collide with each other and with static bodies.
They also have at least three defining parameters in addition to their position and rota-
tion. One is density , or mass —in other words, a measure of how heavy an object is.
Then there is friction —how resistant or slippery the dynamic body is with respect to
moving over surfaces. Finally, there is restitution , which determines the bounciness of
the object. Although impossible in the real world, physics engines can create dynamic
bodies that never lose momentum as they bounce, or even gain speed every time they
bounce off of some other body.
Both dynamic and static bodies have one or more shapes that determine the area the
body encompasses. Most often the shape is a circle or a rectangle, but it can also be a
polygon, a number of vertices forming any complex shape, or merely a straight line.
The shapes of a body determine where other bodies and their shapes collide. And in
turn, each collision generates contact points —the points where the two bodies' shapes
intersect. You can use these contact points to play particle effects or add scratch marks
at exactly the places where the bodies have collided.
Dynamic bodies are animated by the physics engine through applying forces, impulses,
and torque instead of setting their position and rotation directly. Modifying position
and rotation directly is not advised, because physics engines make certain predictions
that no longer hold true if you manually reposition bodies.
Finally, you can connect bodies together using a selection of joints , which limit the
movement of connected bodies in various ways. Some joints may have motors, which
can act as the drive wheel of a car, for example, or as friction for the joint so that the
joint tries to snap back to its original position.
Limitations of Physics Engines
Physics engines have their limits. They have to take shortcuts because the real world is
prohibitively complex to simulate. The use of rigid bodies is an example. In some ex-
treme cases, physics engines may not be able to catch every collision—for example,
when bodies are moving very fast they may tunnel through each other. Although this