pymunk.constraints
Module¶
A constraint is something that describes how two bodies interact with each other. (how they constrain each other). Constraints can be simple joints that allow bodies to pivot around each other like the bones in your body, or they can be more abstract like the gear joint or motors.
This submodule contain all the constraints that are supported by Pymunk.
All the constraints support copy and pickle from the standard library. Custom properties set on a constraint will also be copied/pickled.
Chipmunk has a good overview of the different constraint on youtube which works fine to showcase them in Pymunk as well. http://www.youtube.com/watch?v=ZgJJZTS0aMM
Example:
>>> import pymunk
>>> import pymunk.constraints
>>> s = pymunk.Space()
>>> a,b = pymunk.Body(10,10), pymunk.Body(10,10)
>>> c = pymunk.constraints.PivotJoint(a, b, (0,0))
>>> s.add(c)
- class pymunk.constraints.Constraint(constraint: pymunk._chipmunk.ffi.CData)[source]¶
Bases:
PickleMixin
,TypingAttrMixing
,object
Base class of all constraints.
You usually don’t want to create instances of this class directly, but instead use one of the specific constraints such as the PinJoint.
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- class pymunk.constraints.DampedRotarySpring(a: Body, b: Body, rest_angle: float, stiffness: float, damping: float)[source]¶
Bases:
Constraint
DampedRotarySpring works like the DammpedSpring but in a angular fashion.
- __init__(a: Body, b: Body, rest_angle: float, stiffness: float, damping: float) None [source]¶
Like a damped spring, but works in an angular fashion.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property damping: float¶
How soft to make the damping of the spring.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- property rest_angle: float¶
The relative angle in radians that the bodies want to have
- static spring_torque(spring: DampedRotarySpring, relative_angle: float) float [source]¶
Default damped rotary spring torque function.
- property stiffness: float¶
The spring constant (Young’s modulus).
- property torque_func: Callable[[DampedRotarySpring, float], float]¶
The torque callback function.
The torque callback function is called each time step and is used to calculate the torque of the spring (exclusing any damping).
Defaults to
DampedRotarySpring.spring_torque()
- class pymunk.constraints.DampedSpring(a: Body, b: Body, anchor_a: Tuple[float, float], anchor_b: Tuple[float, float], rest_length: float, stiffness: float, damping: float)[source]¶
Bases:
Constraint
DampedSpring is a damped spring.
The spring allows you to define the rest length, stiffness and damping.
- __init__(a: Body, b: Body, anchor_a: Tuple[float, float], anchor_b: Tuple[float, float], rest_length: float, stiffness: float, damping: float) None [source]¶
Defined much like a slide joint.
- Parameters:
a (Body) – Body a
b (Body) – Body b
anchor_a ((float,float)) – Anchor point a, relative to body a
anchor_b ((float,float)) – Anchor point b, relative to body b
rest_length (float) – The distance the spring wants to be.
stiffness (float) – The spring constant (Young’s modulus).
damping (float) – How soft to make the damping of the spring.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property damping: float¶
How soft to make the damping of the spring.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property force_func¶
The force callback function.
The force callback function is called each time step and is used to calculate the force of the spring (exclusing any damping).
Defaults to
DampedSpring.spring_force()
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- property rest_length: float¶
The distance the spring wants to be.
- static spring_force(spring: DampedSpring, dist: float) float [source]¶
Default damped spring force function.
- property stiffness: float¶
The spring constant (Young’s modulus).
- class pymunk.constraints.GearJoint(a: Body, b: Body, phase: float, ratio: float)[source]¶
Bases:
Constraint
GearJoint keeps the angular velocity ratio of a pair of bodies constant.
- __init__(a: Body, b: Body, phase: float, ratio: float)[source]¶
Keeps the angular velocity ratio of a pair of bodies constant.
ratio is always measured in absolute terms. It is currently not possible to set the ratio in relation to a third body’s angular velocity. phase is the initial angular offset of the two bodies.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property phase: float¶
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- property ratio: float¶
- class pymunk.constraints.GrooveJoint(a: Body, b: Body, groove_a: Tuple[float, float], groove_b: Tuple[float, float], anchor_b: Tuple[float, float])[source]¶
Bases:
Constraint
GrooveJoint is similar to a PivotJoint, but with a linear slide.
One of the anchor points is a line segment that the pivot can slide in instead of being fixed.
- __init__(a: Body, b: Body, groove_a: Tuple[float, float], groove_b: Tuple[float, float], anchor_b: Tuple[float, float]) None [source]¶
The groove goes from groove_a to groove_b on body a, and the pivot is attached to anchor_b on body b.
All coordinates are body local.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- class pymunk.constraints.PinJoint(a: Body, b: Body, anchor_a: Tuple[float, float] = (0, 0), anchor_b: Tuple[float, float] = (0, 0))[source]¶
Bases:
Constraint
PinJoint links shapes with a solid bar or pin.
Keeps the anchor points at a set distance from one another.
- __init__(a: Body, b: Body, anchor_a: Tuple[float, float] = (0, 0), anchor_b: Tuple[float, float] = (0, 0)) None [source]¶
a and b are the two bodies to connect, and anchor_a and anchor_b are the anchor points on those bodies.
The distance between the two anchor points is measured when the joint is created. If you want to set a specific distance, use the setter function to override it.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property distance: float¶
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- class pymunk.constraints.PivotJoint(a: Body, b: Body, *args: Tuple[float, float] | Tuple[Tuple[float, float], Tuple[float, float]])[source]¶
Bases:
Constraint
PivotJoint allow two objects to pivot about a single point.
Its like a swivel.
- __init__(a: Body, b: Body, *args: Tuple[float, float] | Tuple[Tuple[float, float], Tuple[float, float]]) None [source]¶
a and b are the two bodies to connect, and pivot is the point in world coordinates of the pivot.
Because the pivot location is given in world coordinates, you must have the bodies moved into the correct positions already. Alternatively you can specify the joint based on a pair of anchor points, but make sure you have the bodies in the right place as the joint will fix itself as soon as you start simulating the space.
That is, either create the joint with PivotJoint(a, b, pivot) or PivotJoint(a, b, anchor_a, anchor_b).
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- class pymunk.constraints.RatchetJoint(a: Body, b: Body, phase: float, ratchet: float)[source]¶
Bases:
Constraint
RatchetJoint is a rotary ratchet, it works like a socket wrench.
- __init__(a: Body, b: Body, phase: float, ratchet: float) None [source]¶
Works like a socket wrench.
ratchet is the distance between “clicks”, phase is the initial offset to use when deciding where the ratchet angles are.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property angle: float¶
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property phase: float¶
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- property ratchet: float¶
- class pymunk.constraints.RotaryLimitJoint(a: Body, b: Body, min: float, max: float)[source]¶
Bases:
Constraint
RotaryLimitJoint constrains the relative rotations of two bodies.
- __init__(a: Body, b: Body, min: float, max: float) None [source]¶
Constrains the relative rotations of two bodies.
min and max are the angular limits in radians. It is implemented so that it’s possible to for the range to be greater than a full revolution.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max: float¶
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property min: float¶
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- class pymunk.constraints.SimpleMotor(a: Body, b: Body, rate: float)[source]¶
Bases:
Constraint
SimpleMotor keeps the relative angular velocity constant.
- __init__(a: Body, b: Body, rate: float) None [source]¶
Keeps the relative angular velocity of a pair of bodies constant.
rate is the desired relative angular velocity. You will usually want to set an force (torque) maximum for motors as otherwise they will be able to apply a nearly infinite torque to keep the bodies moving.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None
- property rate: float¶
The desired relative angular velocity
- class pymunk.constraints.SlideJoint(a: Body, b: Body, anchor_a: Tuple[float, float], anchor_b: Tuple[float, float], min: float, max: float)[source]¶
Bases:
Constraint
SlideJoint is like a PinJoint, but have a minimum and maximum distance.
A chain could be modeled using this joint. It keeps the anchor points from getting to far apart, but will allow them to get closer together.
- __init__(a: Body, b: Body, anchor_a: Tuple[float, float], anchor_b: Tuple[float, float], min: float, max: float) None [source]¶
a and b are the two bodies to connect, anchor_a and anchor_b are the anchor points on those bodies, and min and max define the allowed distances of the anchor points.
- activate_bodies() None ¶
Activate the bodies this constraint is attached to
- property collide_bodies: bool¶
Constraints can be used for filtering collisions too.
When two bodies collide, Pymunk ignores the collisions if this property is set to False on any constraint that connects the two bodies. Defaults to True. This can be used to create a chain that self collides, but adjacent links in the chain do not collide.
- copy() T ¶
Create a deep copy of this object.
- property error_bias: float¶
The percentage of joint error that remains unfixed after a second.
This works exactly the same as the collision bias property of a space, but applies to fixing error (stretching) of joints instead of overlapping collisions.
Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
- property impulse: float¶
The most recent impulse that constraint applied.
To convert this to a force, divide by the timestep passed to space.step(). You can use this to implement breakable joints to check if the force they attempted to apply exceeded a certain threshold.
- property max: float¶
- property max_bias: float¶
The maximum speed at which the constraint can apply error correction.
Defaults to infinity
- property max_force: float¶
The maximum force that the constraint can use to act on the two bodies.
Defaults to infinity
- property min: float¶
- property post_solve: Callable[[Constraint, Space], None] | None¶
The post-solve function is called after the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def post_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.post_solve = post_solve_func >>> j.post_solve = None
- property pre_solve: Callable[[Constraint, Space], None] | None¶
The pre-solve function is called before the constraint solver runs.
Note that None can be used to reset it to default value.
>>> import pymunk >>> j = pymunk.PinJoint(pymunk.Body(1,2), pymunk.Body(3,4), (0,0)) >>> def pre_solve_func(constraint, space): ... print("Hello from pre-solve") >>> j.pre_solve = pre_solve_func >>> j.pre_solve = None