Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Distance joint definition reference for the Physics Core 2D API

Explore the properties you can use to configure a distance joint in the Editor.
Read time 3 minutesLast updated 13 days ago

Note
This documentation is about writing C# scripts using the
Unity.U2D.Physics
API. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.
Explore the properties you can use to configure a Physics Core 2D API distance joint in the Unity Editor.
A distance joint tries to keep the two connected bodies a certain distance apart.

Property

Sub-property

Description

Local Anchor AN/ASets where one end of the joint connects to the first body.
N/APositionSets the position where the end of the joint connects, relative to the position of the first body.
N/ARotationSets the rotation of the anchor in degrees.
Local Anchor BN/ASets where the other end of the joint connects to the second body.
N/APositionSets the position where the end of the joint connects, relative to the position of the second body.
N/ARotationSets the rotation of the anchor in degrees.
DistanceN/ASets the target distance between the two connected bodies.
Enable SpringN/AEnables Spring Frequency, Spring Damping, Spring Lower Force, and Spring Upper Force. The joint acts as a spring, so it stretches and compresses to try to reach the target distance. The strength of the pull is proportional to the current distance between the bodies. If you disable this property, the joint is rigid, and Enable Motor and Enable Limit have no effect.
Spring FrequencyN/ASets the stiffness of the spring in Hertz (cycles per second). A higher value makes the spring less stiff. The default is 0.
Spring DampingN/ASets how quickly the spring stops pulling or pushing. A higher value makes the spring settle more quickly. The default is 0.
Spring Lower ForceN/ASets the maximum force that the spring applies when it's stretched, in newtons.
Spring Upper ForceN/ASets the maximum force that the spring applies when it's compressed, in newtons.
Enable MotorN/AEnables Motor Speed and Max Motor Force, which make the joint act as a motor to pull or push the two connected bodies. If you disable Enable Spring, this property has no effect.

Note: The motor can drive the bodies beyond the Distance value if it overpowers the spring.
Motor SpeedN/ASets the target motor speed, in meters per second.
Max Motor ForceN/ASets the maximum force that the motor applies to reach the target speed, in newtons.
Enable LimitN/AEnables Min Distance Limit and Max Distance Limit, which limit the distance between the two connected bodies. If you disable Enable Spring, this property has no effect.
Min Distance LimitN/ASets the minimum distance between the bodies in meters.
Max Distance LimitN/ASets the maximum distance between the bodies in meters.
Force ThresholdN/ASets the amount of linear force that creates an
OnJointThreshold2D
event.
Torque ThresholdN/ASets the amount of rotational force that creates an
OnJointThreshold2D
event.
Tuning FrequencyN/ASets the overall stiffness of the joint in Hertz (cycles per second). A higher value makes the joint less stiff.
Tuning DampingN/ASets how quickly overall the joint stops pulling or pushing. A higher value makes the joint settle more quickly.
Draw ScaleN/AScales the joint Unity draws as a debug visualization. For more information, refer to Draw a debug visualization of objects.
Collide ConnectedN/AEnables the shapes creating collision or trigger events when they come into contact with each other. For more information, refer to Collisions and interactions in the Physics Core 2D API.
World DrawingN/ADraws the joint when Unity draws the debug visualization of the world. For more information, refer to Draw a debug visualization of objects.

Additional resources