Body

Base class for all physics bodies. Access via the 'physics' submodule.

Experimental API:

The physics submodule is a VERY experimental and new API that is highly susceptible to breaking changes in the future.

Properties


NameDescriptionType
posThe position of the body in world coordinates.Vec2
rotationThe rotation of the body in radians.float
collision_layerThe body's collision layer (category bits).int
collision_maskThe body's collision mask.int
is_validIndicates whether the body is not destroyed.bool

Methods


Add Collider

add_collider(
    circle: Circle,
    density: float = 1.0,
    friction: float = 0.2,
    restitution: float = 0.0,
    enable_events: bool = False,
    is_sensor: bool = False
) None

Add a circular collider to the body.

Args

  • circle : The circular shape to add as a collider.
  • density : The density of the collider. Defaults to 1.0.
  • friction : The friction coefficient of the collider. Defaults to 0.2.
  • restitution : The restitution (bounciness) of the collider. Defaults to 0.0.
  • enable_events : Whether to enable hit events for this collider. Defaults to False.
  • is_sensor : Whether the collider is a sensor. Defaults to False.

add_collider(
    polygon: Polygon,
    density: float = 1.0,
    friction: float = 0.2,
    restitution: float = 0.0,
    enable_events: bool = False,
    is_sensor: bool = False
) None

Add a polygonal collider to the body.

Args

  • polygon : The polygonal shape to add as a collider.
  • density : The density of the collider. Defaults to 1.0.
  • friction : The friction coefficient of the collider. Defaults to 0.2.
  • restitution : The restitution (bounciness) of the collider. Defaults to 0.0.
  • enable_events : Whether to enable hit events for this collider. Defaults to False.
  • is_sensor : Whether the collider is a sensor. Defaults to False.

add_collider(
    rect: Rect,
    density: float = 1.0,
    friction: float = 0.2,
    restitution: float = 0.0,
    enable_events: bool = False,
    is_sensor: bool = False
) None

Add a rectangular collider to the body.

Args

  • rect : The rectangular shape to add as a collider.
  • density : The density of the collider. Defaults to 1.0.
  • friction : The friction coefficient of the collider. Defaults to 0.2.
  • restitution : The restitution (bounciness) of the collider. Defaults to 0.0.
  • enable_events : Whether to enable hit events for this collider. Defaults to False.
  • is_sensor : Whether the collider is a sensor. Defaults to False.

add_collider(
    capsule: Capsule,
    density: float = 1.0,
    friction: float = 0.2,
    restitution: float = 0.0,
    enable_events: bool = False,
    is_sensor: bool = False
) None

Add a capsule collider to the body.

Args

  • capsule : The capsule shape to add as a collider.
  • density : The density of the collider. Defaults to 1.0.
  • friction : The friction coefficient of the collider. Defaults to 0.2.
  • restitution : The restitution (bounciness) of the collider. Defaults to 0.0.
  • enable_events : Whether to enable hit events for this collider. Defaults to False.
  • is_sensor : Whether the collider is a sensor. Defaults to False.

Get Transform

get_transform() Transform

Get the current transform of the body (position, rotation, and scale).

Returns

Transform : The current transform of the body.

Debug Draw

debug_draw() None

Draw all colliders attached to the body (debug/development only).

Destroy

destroy() None

Destroy the body manually.