Constraints
abstract class CP::Constraint
inherits Reference
#
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.
Direct known subclasses
CP::Constraint::DampedRotarySpring
CP::Constraint::DampedSpring
CP::Constraint::GearJoint
CP::Constraint::GrooveJoint
CP::Constraint::PinJoint
CP::Constraint::PivotJoint
CP::Constraint::RatchetJoint
CP::Constraint::RotaryLimitJoint
CP::Constraint::SimpleMotor
CP::Constraint::SlideJoint
Methods#
#collide_bodies? : Bool
#
Are the two bodies connected by the constraint allowed to collide or not?
(defaults to false)
#error_bias : Float64
#
Rate at which joint error is corrected.
Defaults to (1.0 - 0.1) ** 60.0 meaning that it will correct 10% of the error every 1/60th of a second.
#impulse : Float64
#
Get the most recent impulse applied by this constraint.
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.
#max_bias : Float64
#
The maximum rate at which joint error is corrected.
(defaults to INFINITY)
#max_force : Float64
#
The maximum force that this constraint is allowed to use.
(defaults to INFINITY)
#post_solve(space : Space)
#
The post-solve method that is called before the solver runs (can be overridden in a subclass).
#pre_solve(space : Space)
#
The pre-solve method that is called before the solver runs (can be overridden in a subclass).
class CP::Constraint::DampedRotarySpring
inherits CP::Constraint
#
class CP::Constraint::DampedSpring
inherits CP::Constraint
#
Constructors#
.new(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect, rest_length : Number, stiffness : Number, damping : Number)
#
Defined much like a slide joint.
- anchor_a: Anchor point a, relative to body a
- anchor_b: Anchor point b, relative to body b
- rest_length: The distance the spring wants to be at
- stiffness: The spring constant (Young's modulus)
- damping: How soft to make the damping of the spring
Methods#
class CP::Constraint::GearJoint
inherits CP::Constraint
#
class CP::Constraint::GrooveJoint
inherits CP::Constraint
#
Similar to a pivot joint, but one of the anchors is on a linear slide instead of being fixed.
class CP::Constraint::PinJoint
inherits CP::Constraint
#
Keeps the anchor points at a set distance from one another.
Constructors#
.new(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect)
#
a and b are the two bodies to connect, and anchor_a and anchor_b arethe 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.
Methods#
class CP::Constraint::PivotJoint
inherits CP::Constraint
#
Allows two objects to pivot about a single point.
Constructors#
.new(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect)
#
a and b are the two bodies to connect, and anchor_a and anchor_b are the points in local coordinates where the pivot is located.
.new(a : Body, b : Body, pivot : Vect) : self
#
a and b are the two bodies to connect, and pivot is the point in world coordinates of the pivot.
Methods#
class CP::Constraint::RatchetJoint
inherits CP::Constraint
#
class CP::Constraint::RotaryLimitJoint
inherits CP::Constraint
#
class CP::Constraint::SimpleMotor
inherits CP::Constraint
#
Keeps the relative angular velocity of a pair of bodies constant.
Constructors#
Methods#
#rate : Float64
#
The desired relative angular velocity of the motor.
You will usually want to set a force (torque) maximum for motors as otherwise they will be able to apply a nearly infinite torque to keep the bodies moving.
class CP::Constraint::SlideJoint
inherits CP::Constraint
#
Like pin joints, but have a minimum and maximum distance. A chain could be modeled using this joint. It keeps the anchor points from getting too far apart, but will allow them to get closer together.