physics.Body
pykraken.physics.Body Base class for all physics bodies.
More about physics.Body
A body represents a physical object in the simulation. It can have one or more colliders (shapes) attached to it and participates in collision detection and resolution. This is an abstract base class — use RigidBody, StaticBody, or CharacterBody instead.
At a glance
10 membersReference
PYTHON APIConstructor
methodphysics.Body(/, *args, **kwargs)Initialize self. See help(type(self)) for accurate signature.
collision_layer
propertycollision_layer: intThe body's collision layer (category bits).
collision_mask
propertycollision_mask: intThe body's collision mask.
is_valid
propertyis_valid: boolIndicates whether the body is not destroyed.
pos
propertypos: Vec2The position of the body in world coordinates.
rotation
propertyrotation: floatThe rotation of the body in radians.
add_collider(self, circle: Circle, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> Noneadd_collider(self, polygon: Polygon, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> Noneadd_collider(self, rect: Rect, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> Noneadd_collider(self, capsule: Capsule, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> NoneOverloaded function.
add_collider(self, circle: Circle, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> None
Add a circular collider to the body.
Args
- circle (
Circle) — The circular shape to add as a collider. - density (
float, optional) — The density of the collider. Defaults to 1.0. - friction (
float, optional) — The friction coefficient of the collider. Defaults to 0.2. - restitution (
float, optional) — The restitution (bounciness) of the collider. Defaults to 0.0. - enable_events (
bool, optional) — Whether to enable hit, contact, and sensor events for this collider. Defaults to False. - is_sensor (
bool, optional) — Whether the collider is a sensor. Defaults to False.
add_collider(self, polygon: Polygon, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> None
Add a polygonal collider to the body.
Args
- polygon (
Polygon) — The polygonal shape to add as a collider. - density (
float, optional) — The density of the collider. Defaults to 1.0. - friction (
float, optional) — The friction coefficient of the collider. Defaults to 0.2. - restitution (
float, optional) — The restitution (bounciness) of the collider. Defaults to 0.0. - enable_events (
bool, optional) — Whether to enable hit, contact, and sensor events for this collider. Defaults to False. - is_sensor (
bool, optional) — Whether the collider is a sensor. Defaults to False.
add_collider(self, rect: Rect, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> None
Add a rectangular collider to the body.
Args
- rect (
Rect) — The rectangular shape to add as a collider. - density (
float, optional) — The density of the collider. Defaults to 1.0. - friction (
float, optional) — The friction coefficient of the collider. Defaults to 0.2. - restitution (
float, optional) — The restitution (bounciness) of the collider. Defaults to 0.0. - enable_events (
bool, optional) — Whether to enable hit, contact, and sensor events for this collider. Defaults to False. - is_sensor (
bool, optional) — Whether the collider is a sensor. Defaults to False.
add_collider(self, capsule: Capsule, density: float = 1.0, friction: float = 0.20000000298023224, restitution: float = 0.0, enable_events: bool = False, is_sensor: bool = False) -> None
Add a capsule collider to the body.
Args
- capsule (
Capsule) — The capsule shape to add as a collider. - density (
float, optional) — The density of the collider. Defaults to 1.0. - friction (
float, optional) — The friction coefficient of the collider. Defaults to 0.2. - restitution (
float, optional) — The restitution (bounciness) of the collider. Defaults to 0.0. - enable_events (
bool, optional) — Whether to enable hit, contact, and sensor events for this collider. Defaults to False. - is_sensor (
bool, optional) — Whether the collider is a sensor. Defaults to False.
destroy
methoddestroy(self) -> NoneDestroy the body manually.
get_colliders
methodget_colliders(self) -> list[physics.Collider]Return non-owning handles for this body's collider shapes.
get_transform
methodget_transform(self) -> TransformGet the current transform of the body (position, rotation, and scale).
Returns
- Transform — The current transform of the body.