Applications of Calculus: Physics Engines in Video Games
Physics engines allow video game characters to move in realistic virtual environments, so that if your character throws or jumps or drives a car off a cliff, the result will mimic reality. To perform this task, the physics engine periodically updates the locations of objects, such that the trajectories of objects follow physical laws.
For early games like pong, the physical laws were simple. In pong, the ball travels with a constant velocity $v$ at an angle $\theta,$ and it deflects off paddles such that its incoming angle is equal to its outgoing angle.
The velocity affects the ball’s $x$ and $y$ positions as follows:
Using differentials, we write this as
The updates for a ball’s motion across the grid, then, are
where $\Delta t$ is the timestep (the fraction of a second to be simulated) and $\theta$ is updated according to
whenever the ball hits a surface.
In more complex modern games, however, game objects are assigned properties like mass and friction constants, so that their trajectories can be calculated in response to physical forces. This is made possible through Newton’s second law of motion, which describes how a force $F$ affects an object’s velocity $v.$
In 1 dimension, the object’s velocity $v$ then affects its position $x$ according to
Thus, the update equations for an object experiencing a force in 1 dimension are given by