Game Development Reference
In-Depth Information
general, a control system 12 takes as input a function of time that represents
some target value. For example, our camera code might compute a desired
camera position based on the player's position each frame; some AI code
might determine an exact targeting angle for an enemy; we may have a
desired player character velocity based on the instantaneous amount of
control stick deflection; or we might have a desired screen-space position
for some highlight effect, based on the currently selected choice in a menu.
In any case, the current value of the input signal is known as the set point
in control system terminology. The set point is essentially the rest position
of the spring, and the input signal is like somebody taking the other end of
the spring and yanking it around. (So it's similar to a driving force, only
usually what we have is a function describing a position rather than a force
or acceleration.)
The job of any control system is to take this input signal and produce
an output signal. To go back to our earlier examples, the output signal
might be the actual camera position to use for each frame, or the actual
animated targeting angle the enemy will use to aim the weapon, the ac-
tual player character velocity, or the actual screen-space position of the
highlight. For many control systems, the actual position and set point are
not used; rather, only the error is needed. Of course, an obvious question
is, if we know the “desired” value, why don't we just use that directly?
Because it's too jerky. In the same way that the shocks and springs on
a car (a classic example of a spring-damper system) don't just pass along
the elevation of the road directly to the car, a control system in a video
game is often designed to “smooth out the bumps” caused by sudden state
changes that might make the camera snap to a new position or the player
jerk into motion. The camera or screen-space highlight are nonphysical
examples in which the quantity of “mass” is not really appropriate and
is dropped. But the differential equations are still the same, and they
have the same solution. Stripped of the spring metaphor, we are left with
what is known as a PD controller. The P stands for proportional, and
this is the spring part of the controller, since it acts proportional to the
current error. The damper is the D part, which stands for derivative, be-
cause the action of the damper at any given instant is proportional to the
derivative (the velocity). PD controllers (and their more robust cousin,
the PID controller, where the I stands for integral and is used to remove
steady-state error) are broadly applicable tools; they have been standard
engineering tools for decades (centuries?) and are well understood. Never-
theless, they are one of the most frequently reinvented wheels in video game
programming.
12 This is not the broadest possible definition of “control system,” but it is the most
common one.
Search WWH ::




Custom Search