physics.RigidBody
pykraken.physics.RigidBody A dynamic physics body that responds to forces, impulses, and collisions.
More about physics.RigidBody
Rigid bodies are fully simulated by the physics engine. They have mass, velocity, and can be affected by gravity, forces, and impulses. Use this for objects like projectiles, crates, or anything that should move realistically.
Inherits Body
At a glance
25 membersConstructormethodangular_dampingpropertyangular_velocitypropertycollision_layerpropertycollision_maskpropertyfixed_rotationpropertyis_awakepropertyis_bulletpropertyis_validpropertylinear_dampingpropertylinear_velocitypropertymasspropertypospropertyrotationpropertyadd_collidermethodapply_angular_impulsemethodapply_forcemethodapply_force_to_centermethodapply_linear_impulsemethodapply_linear_impulse_to_centermethodapply_torquemethoddestroymethodget_collidersmethodget_transformmethodwakemethodReference
PYTHON APIConstructor
methodphysics.RigidBody(world: physics.World)Create a new rigid body in the specified world.
The body is created at the origin with no colliders. Add colliders with
add_collider before the body can interact with other objects.
Args
- world (
World) — The physics world to create the body in.
angular_damping
propertyangular_damping: floatThe angular damping of the body.
angular_velocity
propertyangular_velocity: floatThe angular velocity of the body.
collision_layer
propertycollision_layer: intThe body's collision layer (category bits).
collision_mask
propertycollision_mask: intThe body's collision mask.
fixed_rotation
propertyfixed_rotation: boolWhether the body has fixed rotation.
is_awake
propertyis_awake: boolWhether the body is currently awake and simulating.
is_bullet
propertyis_bullet: boolWhether CCD is enabled for this body.
is_valid
propertyis_valid: boolIndicates whether the body is not destroyed.
linear_damping
propertylinear_damping: floatThe linear damping of the body.
linear_velocity
propertylinear_velocity: Vec2The linear velocity of the body.
mass
propertymass: floatThe mass of the body.
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.
apply_angular_impulse
methodapply_angular_impulse(self, impulse: float, wake: bool = True) -> NoneApply an angular impulse to the body.
Args
- impulse (
float) — The angular impulse to apply. - wake (
bool, optional) — Whether to wake the body if it's sleeping. Defaults to True.
apply_force
methodApply a force to the body at a specific point.
Args
- force (
Vec2) — The force vector to apply. - point (
Vec2) — The point (in world coordinates) where the force is applied. - wake (
bool, optional) — Whether to wake the body if it's sleeping. Defaults to True.
apply_force_to_center
methodapply_force_to_center(self, force: Vec2, wake: bool = True) -> NoneApply a force to the center of mass of the body.
Args
- force (
Vec2) — The force vector to apply. - wake (
bool, optional) — Whether to wake the body if it's sleeping. Defaults to True.
apply_linear_impulse
methodApply a linear impulse to the body at a specific point.
Args
- impulse (
Vec2) — The impulse vector to apply. - point (
Vec2) — The point (in world coordinates) where the impulse is applied. - wake (
bool, optional) — Whether to wake the body if it's sleeping. Defaults to True.
apply_linear_impulse_to_center(self, impulse: Vec2, wake: bool = True) -> NoneApply a linear impulse to the center of mass of the body.
Args
- impulse (
Vec2) — The impulse vector to apply. - wake (
bool, optional) — Whether to wake the body if it's sleeping. Defaults to True.
apply_torque
methodapply_torque(self, torque: float, wake: bool = True) -> NoneApply a torque to the body.
Args
- torque (
float) — The torque to apply. - wake (
bool, optional) — Whether to wake the body if it's sleeping. Defaults to True.
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.
wake
methodwake(self) -> NoneManually wake the body from sleep.