Skip to main content

joint2d

2d · physics · 18 properties · 2D

Holds this node's body to another one in 2D: a hinge, a slider, a rope, a spring, or a generic joint you lock axis by axis. Both ends need a body2d.

In a scene, joint2d is the node key that applies it. A script reaches the same properties through node.joint2d.get() and node.joint2d.set(table).

Properties

propertytypedefaultdescription
anchorvec2[0,0]Where the joint attaches on this node, in its own space
axisvec2[1,0]The direction a prismatic joint slides along
bodynodeThe node at the joint's other end; this node is the first end
break_forcefloat0The pull that snaps the joint and calls on_joint_break; 0 never breaks At least 0.
contactsboolfalseLet the two joined bodies collide with each other
dampingfloat1How quickly the motion settles, for a spring joint or a motor At least 0.
enabledbooltrueHold the two bodies together at all
kindenumfixedHow the two bodies may move relative to each other One of fixed, revolute, prismatic, rope, spring, pin_slot, generic. Scene shorthand: kind's value can be given as the component's whole value.
lengthfloat0The rope's greatest length, or the spring's rest length At least 0.
limitsvec2[0,0]How far the joint may travel, as a low and a high; equal values mean no limit
locked_axesflags[]Which of the three freedoms a generic joint takes away One of x, y, ang_x.
motorenumoffDrive the joint towards a speed, towards a position, or not at all One of off, velocity, position.
motor_max_forcefloat0The most force the motor may use; 0 means as much as it takes At least 0.
motor_modelenumaccelerationWhether the motor's strength is felt as an acceleration, ignoring mass, or as a force One of acceleration, force.
motor_targetfloat0The speed or the position the motor drives towards
other_anchorvec2[0,0]Where it attaches on the other node, in that node's space
solverenumimpulseimpulse holds any arrangement, loops included; reduced never drifts and can be solved for inverse kinematics, but cannot close a loop One of impulse, reduced.
stiffnessfloat0Spring stiffness, for a spring joint or a position motor At least 0.

Script functions

Methods of node.joint2d, the handle a node carrying this component exposes. Each is also a free function on its module, taking the node as its first argument. Every handle also has get(), set(table), has() and remove().

From physics2d:

methodwhat it does
add_joint(any)Tie this node's body to another with a 2D joint, from a joint2d table.
joint_impulse() -> floatHow hard the joint is pulling right now.
remove_joint()Undo the node's joint, leaving both bodies free.
set_joint_limits(float, float)Set how far the joint may travel.
set_motor_position(float, float, float)Drive the joint towards an angle or a distance, with a spring's stiffness and damping.
set_motor_velocity(float, float)Drive the joint towards a speed: how a wheel is powered.