Game Development Reference
In-Depth Information
3.3.1
T HE U PDATE E QUATIONS
We need to update both position and velocity; each is handled slightly differently.
Position Update
In chapter 2 we saw that integrating the acceleration twice gives us this equation for
the position update:
1
2 ¨
p =
+ ˙
pt 2
p
pt
+
This is a well-known equation seen in high school and undergraduate textbooks on
applied mathematics.
We could use this equation to perform the position update in the engine, with
code something like
object.position += object.velocity * time +
object.acceleration * time * time * 0.5;
or
object.position.addScaledVector(object.velocity, time);
object.position.addScaledVector(object.acceleration, time * time * 0.5);
In fact, if we are running the update every frame, then the time interval will be
very small (typically 0.033 s for a 30-frames-per-second game). If we look at the ac-
celeration part of this equation, we are taking half of the squared time (which gives
0.0005). This is such a small value that it is unlikely the acceleration will have much
of an impact on the change in position of an object.
For this reason we typically ignore the acceleration entirely in the position update
and use the simpler form
p =
+ ˙
p
pt
This is the equation we will use in the integrator throughout this topic.
If your game regularly uses short bursts of huge accelerations, then you might
be better off using the longer form of the equation. If you do intend to use huge
accelerations, however, you are likely to get all sorts of other accuracy problems in
any case: all physics engines typically become unstable with very large accelerations.
Velocity Update
The velocity update has a similar basic form
p = ˙
˙
+ ¨
p
pt
Search Nedrilad ::

Custom Search