2D Joint

The physics system contains a series of joint components for connecting two rigid bodies. Joint components can be used to simulate the interaction between real-world objects such as hinges, pistons, ropes, wheels, pulleys, motor vehicles, chains, etc. Learning how to use joint components can create a realistic and interesting scenario.

Note.

  1. Joint components are not available in the Builtin 2D physics module.
  2. Joint components are required with rigid body to work correctly. As shown in the following figure.

    with-body

Adding joints

Click the Add Component button on the Inspector panel and enter the component name of the 2D joint.

add-joint

Common Properties of Joints

Although each joint has different representations, they also share some common properties:

PropertiesDescription
ConnectedBodyThe rigid body at the other end of the joint connected
Note: In v3.7, if this property is not set, it will take the origin [0, 0] piont by default to be consistent with the implementation of the constraint in 3D Physics
AnchorThe anchor point of the rigid body connected to the local end of the joint
ConnectedAnchorAnchor point of the rigid body at the other end of the joint connected
CollideConnectedCan the rigid bodies at the two ends of the joint collide with each other

Each joint needs to connect two rigid bodies to perform its function. We consider the rigid body hanging under the same node of the joint as the joint’s home end, and ConnectedBody as the rigid body on the other end. Usually, each rigid body picks a location around itself and sets it as an anchor point. Depending on the type of joint component, the anchor point determines the center of rotation of the object, or a coordinate point used to maintain a certain distance, etc.

The CollideConnected property is used to determine whether the rigid bodies at the ends of the joints need to continue to follow the regular collision rules.

If you are now going to make a ragdoll, you might want the thighs and lower legs to partially overlap and then connect together at the knees, then you would set the CollideConnected property to false. If you are going to make a lift and want the lift platform and floor to collide, then you would set the CollideConnected property to true.

Adjusting Anchor Points

Anchor points can be adjusted in the scene by clicking and dragging the gizmo-a to adjust the Anchor property, and by gizmo-b to adjust the ConnectedAnchor.

gizmo

DistanceJoint2D

Click Add Component on the Inspector panel and enter DistanceJoint2D to add a distance joint.

distance-joint

DistanceJoint constrains the rigid bodies at both ends of the joint to a maximum range. Beyond this range, the motion of the rigid bodies will interact with each other.

distance-joint

Below this range, they will not interact with each other.

dis

Properties

PropertiesDescription
MaxLengthThe maximum distance
AutoCalcDistanceWhether to automatically calculate the distance between two rigid bodies connected by a joint

FixedJoint2D

Click Add Component on the Inspector panel and enter FixedJoint2D to add a fixed joint.

fixed

Fixed Joint holds two points on two objects together based on their initial angles.

fixed

Properties

PropertiesDescription
Frequencycoefficient of elasticity
DampingRatioDamping, indicating the resistance to return to the initial state after the joint has been deformed

HingeJoint2D

Click Add Component on the Inspector panel and enter HingeJoint2D to add a hinge joint.

hinge

A Hinge Joint can be seen as a hinge or peg, where the rigid body rotates around a shared point.

hinge

Properties

PropertiesDescription
EnableLimitWhether to enable the limit of the joint
LowerAngleThe minimum limit of the angle
UpperAngleThe maximum limit of the angle
EnableMotorWhether to turn on the joint motor
MaxMotorTorqueMaximum torque that can be applied to a rigid body
MotorSpeedDesired motor speed

When motor speed is enabled, the jointed rigid body will try to gradually accelerate to the desired speed.

speed

motor

RelativeJoint2D

Relative joints can be added by clicking Add Component on the Inspector panel and entering RelativeJoint2D.

relative

Relative Joint controls the relative motion between two rigid bodies.

relative

Properties

PropertiesDescription
MaxForceThe maximum force value that can be applied to a rigid body
MaxTorqueThe maximum torque value that can be applied to the rigid body
CorrectionFactorPosition correction factor, in the range [0, 1]
LinearOffsetThe position offset of the rigid body at the other end of the joint with respect to the rigid body at the starting end
AngularOffsetThe angle offset of the rigid body at the other end of the joint with respect to the starting rigid body
AutoCalcOffsetAutomatically calculate the angularOffset and linearOffset between two rigid bodies connected by a joint

SliderJoint2D

Click Add Component on the Inspector panel and enter SliderJoint2D to add a sliding joint.

slider

With a Slider Joint, the angle between the two rigid bodies is fixed and they can only slide on a specified axis. The blue square in the figure below is subject to gravity but can actually only move in the set direction due to the constraints of the joint.

slider

Properties

PropertiesDescription
AngleDirection of sliding
AutoCalcAngleAutomatically calculates the sliding direction based on the two rigid bodies connected
EnableMotorWhether to turn on the joint motor
MaxMotorForceThe maximum force that can be applied to the rigid body
MotorSpeedDesired motor speed
EnableLimitEnables or disables the distance limit of the joint
LowerLimitThe minimum value that the rigid body can move
UpperLimitThe maximum value that the rigid body can move

SpringJoint2D

Click Add Component on the Inspector panel and enter SpringJoint2D to add a spring joint.

spring

The Spring Joint connects objects at the ends of the joint like a spring.

spring

Properties

PropertiesDescription
FrequencyElasticity factor
DamingRatioDamping, the resistance to return to the initial state after the joint has been deformed
DistanceThe distance between the two ends of the joint
AutoCalcDistanceAutomatically calculates the distance between two rigid bodies connected by a joint.

WheelJoint2D

Click Add Component on the Inspector panel and enter WheelJoint2D to add a wheel joint.

wheel

The Wheel Joint is used to simulate the wheels of a motor vehicle.

wheel

Consider enabling EnableMotor for both front and rear wheels in the case of simulated realistic 4WD, and EnableMotor for only the drive wheels in the case of non-4WD. The illustration shows only the front wheels with EnableMotor enabled, thus simulating a front-wheel drive situation.

Properties

PropertiesDescription
AngleWheel vibration direction
EnableMotorWhether to enable the joint motor
MaxMotorTorqueThe maximum torque that can be applied to the rigid body
MotorSpeedDesired motor speed
FrequencyElasticity factor
DampingRatioDamping, indicating the resistance to return to the initial state after joint deformation