Class Joints2D
Box2D's seven joint types with world-space anchors: say where the pivot is and which way the axis points, and the local frames each body needs are worked out here.
public static class Joints2D
- Inheritance
-
Joints2D
Remarks
A raw joint definition hides its bodies inside a base field and expresses each anchor
as a local frame: a point and a rotation in that body's own space, which have to be
derived from the world pivot with the body's current transform. Every Box2D sample repeats that
derivation; these factories do it once. The pose at creation is the joint's zero: a revolute
joint's angle, a prismatic joint's translation and a weld's rest pose are all measured from
where the bodies were when the joint was made.
Options records carry the per-type knobs by the names Box2D uses. A property left
null keeps Box2D's default, so new RevoluteJointOptions { EnableMotor =
true, MotorSpeed = 2 } changes exactly two things. Angles are in radians, as in Box2D.
The static methods take a Box2D.NET.B2WorldId and body ids, like PhysicsQueries2D; Joints offers the same with entities.
Methods
CreateDistance(B2WorldId, B2BodyId, B2BodyId, Vector2, Vector2, DistanceJointOptions?)
A rod between two anchors, one on each body. The rest length defaults to their distance at creation; a spring makes it soft, a limit with a spring makes it a rope.
public static B2JointId CreateDistance(B2WorldId world, B2BodyId a, B2BodyId b, Vector2 worldAnchorA, Vector2 worldAnchorB, DistanceJointOptions? options = null)
Parameters
worldB2WorldIdaB2BodyIdbB2BodyIdworldAnchorAVector2worldAnchorBVector2optionsDistanceJointOptions
Returns
- B2JointId
CreateFilter(B2WorldId, B2BodyId, B2BodyId)
No constraint at all: the two bodies simply never collide with each other. For the links of a chain or the parts of a ragdoll.
public static B2JointId CreateFilter(B2WorldId world, B2BodyId a, B2BodyId b)
Parameters
worldB2WorldIdaB2BodyIdbB2BodyId
Returns
- B2JointId
CreateMotor(B2WorldId, B2BodyId, B2BodyId, Vector2?, MotorJointOptions?)
Drives b relative to a. With a pivot, both frames sit
there and the spring pulls that point on B toward that point on A - the mouse-drag shape;
without one, the frames are the body origins.
public static B2JointId CreateMotor(B2WorldId world, B2BodyId a, B2BodyId b, Vector2? worldPivot = null, MotorJointOptions? options = null)
Parameters
worldB2WorldIdaB2BodyIdbB2BodyIdworldPivotVector2?optionsMotorJointOptions
Returns
- B2JointId
CreatePrismatic(B2WorldId, B2BodyId, B2BodyId, Vector2, Vector2, PrismaticJointOptions?)
A slider: b moves along worldAxis through
worldPivot, fixed in a's frame, without turning.
public static B2JointId CreatePrismatic(B2WorldId world, B2BodyId a, B2BodyId b, Vector2 worldPivot, Vector2 worldAxis, PrismaticJointOptions? options = null)
Parameters
worldB2WorldIdaB2BodyIdbB2BodyIdworldPivotVector2worldAxisVector2optionsPrismaticJointOptions
Returns
- B2JointId
CreateRevolute(B2WorldId, B2BodyId, B2BodyId, Vector2, RevoluteJointOptions?)
A hinge at worldPivot: the bodies turn about it and nothing else.
public static B2JointId CreateRevolute(B2WorldId world, B2BodyId a, B2BodyId b, Vector2 worldPivot, RevoluteJointOptions? options = null)
Parameters
worldB2WorldIdaB2BodyIdbB2BodyIdworldPivotVector2optionsRevoluteJointOptions
Returns
- B2JointId
CreateWeld(B2WorldId, B2BodyId, B2BodyId, Vector2, WeldJointOptions?)
Glues the bodies together at worldPivot in their current relative pose.
public static B2JointId CreateWeld(B2WorldId world, B2BodyId a, B2BodyId b, Vector2 worldPivot, WeldJointOptions? options = null)
Parameters
worldB2WorldIdaB2BodyIdbB2BodyIdworldPivotVector2optionsWeldJointOptions
Returns
- B2JointId
CreateWheel(B2WorldId, B2BodyId, B2BodyId, Vector2, Vector2, WheelJointOptions?)
A wheel on a suspension: wheel turns about worldPivot
and slides along worldAxis - the suspension direction, usually straight
up - relative to chassis.
public static B2JointId CreateWheel(B2WorldId world, B2BodyId chassis, B2BodyId wheel, Vector2 worldPivot, Vector2 worldAxis, WheelJointOptions? options = null)
Parameters
worldB2WorldIdchassisB2BodyIdwheelB2BodyIdworldPivotVector2worldAxisVector2optionsWheelJointOptions
Returns
- B2JointId
Destroy(B2JointId, bool)
Removes a joint. Safe on a joint that is already gone.
public static void Destroy(B2JointId joint, bool wakeBodies = true)
Parameters
jointB2JointIdThe joint.
wakeBodiesboolWake the bodies it connected, so they react to being freed.
GetAnchors(B2JointId)
The joint's two anchors in world space right now, for drawing it. They coincide for a hinge or a weld and sit apart for a rod.
public static (Vector2 A, Vector2 B) GetAnchors(B2JointId joint)
Parameters
jointB2JointId
Returns
IsValid(B2JointId)
Whether the joint still exists - it goes when either body is destroyed.
public static bool IsValid(B2JointId joint)
Parameters
jointB2JointId