Source

wasabi-physics / doc / physics.rst

Physics Simulation

:py:class:`wasabi.physics.Physics` is physical simulation which given a (small) time step will update the position and velocity vectors of a number of :py:class:`Bodies <Body>` that have been registered with the simulation.

The basic pattern for using the physics engine is as follows:

  1. Set up the :py:class:`Physics` with all the :py:class:`dynamic bodies <Body>` and :py:class:`static geometry <StaticBody>` that will be interacting in the world.

Then, each 'frame':

  1. Apply any forces that are acting on the bodies.
  2. Call :py:meth:`Phsyics.update` to update the simulation.
  3. Retrieve the updated positions of the bodies.

Simulation

Bodies

Bodies are the objects that can be added to the simulation. These may represent controllable players or simply movable scenery.

Collision Groups and Masks

To allow for types of objects that don't collide with every other type of object, each :py:class:`Body` object can be configured with a bitvector that defines its collision group, and a bitvector that defines the groups with which it will collide.

For example, if we define collision groups as follows:

FOREGROUND = 1
BACKGROUND = 1 << 2

Then we could create a body that only exists in the background by setting its groups to BACKGROUND. If it should collide only with other background objects we should set its mask to BACKGROUND also.

Similarly we could create an body that will only collide with foreground objects by setting mask to FOREGROUND, or we could | (or) together the groups to create an object that will collide with both groups:

mask=FOREGROUND | BACKGROUND

Note

It is possible for one object to collide with another object whose groups do not match its mask, because the condition may be true for the other object.