Game Development Reference

In-Depth Information

This kind of equation is called a “differential equation.” It links the different dif-

ferentials together, sometimes with the original quantity: in this case the second dif-

ferential

p
and the original
p
. Differential equations can sometimes be solved to give

an expression for just the original quantity. In our case the equation can be solved to

give us an expression that links the position with the current time.
2
The expression is

solved to give

¨

p
0

χ

p
t
=

p
0
cos
(χ t)

+

sin
(χ t)

[6.4]

where
p
0
is the position of the end of the spring
relative to the natural length
at the

start of the prediction, and

˙

p
0
is the velocity at the same time.

We can substitute into equation 6.4 the time interval we are interested in (i.e., the

duration of the current frame), and work out where the spring would end up if it

were left to do its own thing. We can then create a force that is just big enough to get

it to the correct location over the duration of the frame. If the final location needs to

be
p
t
, then the force to get it there would be

=

¨

f

m

p

and the acceleration

p
is given by

¨

p
0
)
1

p

¨

=

(
p
t
−

t
2
− ˙

p
0

[6.5]

Note that, although this gets the particle to the correct place, it doesn't get it there

with the correct speed. We'll return to the problems caused by this failing at the end

of the section.

Damped Harmonic Motion

A real spring experiences drag as well as spring forces. The spring will not continue

to oscillate forever to the same point. Its maximum extension will get less each time,

until eventually it settles at the rest length. This gradual decrease is caused by the drag

that the spring experiences.

When we run our physics engine normally, the drag will be incorporated in the

damping parameter. When we predict the behavior of the spring using the previous

formula this does not happen.

2.
Not all differential equations have a simple solution, although most simple equations of the preceding

kind do. Solving differential equations can involve applying a whole range of different techniques and is

beyond the scope of this topic. When necessary I will provide the answers needed for the physics simulator.

If you want to understand more about how I get these answers, you can refer to any undergraduate-level

calculus text for more details.