Body
API reference for Body. 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
| Name | Description | Type |
|---|---|---|
collision_layer | The body's collision layer (category bits). | int |
collision_mask | The body's collision mask. | int |
is_valid | Indicates whether the body is not destroyed. | bool |
pos | The position of the body in world coordinates. | Vec2 |
rotation | The rotation of the body in radians. | float |
Methods
Add Collider
add_collider(
circle: Circle,
density: SupportsFloat = 1.0,
friction: SupportsFloat = 0.2,
restitution: SupportsFloat = 0.0,
enable_events: bool = False,
is_sensor: bool = False
) → NoneAdd 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: SupportsFloat = 1.0,
friction: SupportsFloat = 0.2,
restitution: SupportsFloat = 0.0,
enable_events: bool = False,
is_sensor: bool = False
) → NoneAdd 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: SupportsFloat = 1.0,
friction: SupportsFloat = 0.2,
restitution: SupportsFloat = 0.0,
enable_events: bool = False,
is_sensor: bool = False
) → NoneAdd 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: SupportsFloat = 1.0,
friction: SupportsFloat = 0.2,
restitution: SupportsFloat = 0.0,
enable_events: bool = False,
is_sensor: bool = False
) → NoneAdd 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.
Debug Draw
debug_draw() → NoneDraw all colliders attached to the body (debug/development only).
Destroy
destroy() → NoneDestroy the body manually.
Get Transform
get_transform() → TransformGet the current transform of the body (position, rotation, and scale).
Returns
Transform : The current transform of the body.