Skip to main content

Gravitational force

By default, the physics engine applies a downward force to all dynamic physics bodies. This force is called gravity. You can change the gravity by setting the gravity property of the Physics instance.

The default gravity is a Vector with dx and dy components of 0 and 1, respectively. This means that the force of gravity is 0 in the horizontal direction and 1 in the vertical direction. In other words, the force of gravity is downward.

note

In m2c2kit, the origin is at the top-left corner of the scene. Thus, the positive dy direction is downward.

Changing gravity

To change the gravity, set the gravity property of the Physics instance.

The moon's gravity is 1/6 that of earth's. The below example simulates the moon's gravity by setting the gravity property to { dx: 0, dy: .1666}.

Loading...