Game Physics JS: Laws of motion

Particles

A particle has a position, velocity and acceleration, but no orientation.

Newton's first laws of motion

1) An object continues with a constant velocity unless a force acts upon it.

The value that stays constant is actually the momentum (velocity * mass). More details later.

Because of rounding errors in computer simulations, all movements tend to accelerate.

As a result, the velocity must be corrected at each frame with a damping coefficient (ex: 0.999).

A smaller damping value can be used to reproduce real world's drag forces (ex: 0.8).

2) A force acting on an object produces acceleration that is inversely proportional to the object’s mass.

All forces applied to an object alter its acceleration, proportionally to its mass.

Velocity and position are then updated by integration.

f = ma = mp̈ ⟺ p̈ = 1/m f

Instead of storing tha particle's mass, we will use inverseMass (1/m).

If the inverseMass is zero, the object will be immovable.

Gravity

Gravity is a downwards force, around 10m/s² on Earth, often higher in video games (ex: 15 to 20m/s²).

g = [0, -g, 0];

Integrator

In a physics engine, the integrator updates velocity and position of every object at each frame.

Position update

As we saw in Chapter 2, position can be approached with the velocity only:

p' = p + ̇pt

Velocity update

The velocity can be updated using the acceleration and the damping parameter d (to the power of elapsed time):

̇p' = ̇pdt + ̈pt

JavaScript implementation in chapter 5.



Next