Joint Module
- class box2d.joint.Joint(world, body_a, body_b, collide_connected=False)[source]
Base class for all physics joints connecting two rigid bodies.
Manages the lifecycle and common properties of constraints between bodies, such as anchors and collision handling between connected bodies.
- __init__(world, body_a, body_b, collide_connected=False)[source]
Initialize a joint between two bodies.
- Parameters:
world – The physics world where the joint exists
body_a – First body to connect (must be movable/dynamic)
body_b – Second body to connect (can be static or dynamic)
collide_connected – Whether connected bodies should collide with each other
- property anchor_a
Local connection point on the first body.
- Returns:
Position where the joint attaches to body_a in its local coordinates
- Return type:
- property anchor_b
Local connection point on the second body.
- Returns:
Position where the joint attaches to body_b in its local coordinates
- Return type:
- property body_a
Get the first body connected by this joint.
- Returns:
The dynamic body that initiated the joint connection
- Return type:
- property body_b
Get the second body connected by this joint.
- Returns:
The partner body (can be static or dynamic)
- Return type:
- property collide_connected: bool
Check if connected bodies can collide with each other.
- Returns:
True if connected bodies can collide, False otherwise
- Return type:
bool
- property constraint_force
Current force exerted by the joint to maintain its constraint.
- Returns:
Constraint force vector in world coordinates
- Return type:
- property constraint_torque
Current torque exerted by the joint to maintain rotation constraints.
- Returns:
Constraint torque value
- Return type:
float
- property is_valid
Check if the joint is currently active in the simulation.
- Returns:
True if the joint still connects its bodies, False if it has been removed or destroyed
- class box2d.joint.MouseJoint(world, body, target, max_force=1000.0, damping_ratio=0.7, hertz=5.0)[source]
Interactive joint for dragging bodies with mouse-like movement.
Designed for smoothly pulling dynamic bodies to target positions, with spring-like behavior controls for realistic manipulation.
- __init__(world, body, target, max_force=1000.0, damping_ratio=0.7, hertz=5.0)[source]
Create a drag-and-move joint for interactive manipulation.
- Parameters:
world – The physics world where the joint exists
body – Dynamic body to be dragged
target – Initial world position (x,y) to pull toward
max_force – Maximum force allowed for movement
damping_ratio – Spring damping
hertz – Spring stiffness in Hz
- property damping_ratio
Spring damping controlling movement smoothness.
- property max_force
Maximum pulling force available to move the body.