Version: 2021.1
Slider Joint 2D
Target Joint 2D

Spring Joint 2D

Switch to Scripting

The Spring Joint__ 2D__ component allows two game objects controlled by rigidbody physics to be attached together as if by a spring. The spring will apply a force along its axis between the two objects, attempting to keep them a certain distance apart.

Property: Function:
Enable Collision Can the two connected objects collide with each other? Check the box for yes.
Connected Rigid Body Specify here the other object this joint connects to. Leave this as None and the other end of the joint will be fixed at a point in space defined by the Connected Anchor setting. Select the circle to the right of the field to view a list of objects to connect to.
Auto Configure Connected Anchor Check this box to automatically set the anchor location for the other object this joint connects to. (Check this instead of completing the Connected Anchor fields.)
AnchorA UI layout tool that fixes a UI element to a parent element. Anchors are shown as four small triangular handles in the Scene View and anchor information is also shown in the Inspector. More info
See in Glossary
The place (in terms of X, Y co-ordinates on the RigidBodyA component that allows a GameObject to be affected by simulated gravity and other forces. More info
See in Glossary
) where the end point of the joint connects to this object.
Connected Anchor The place (in terms of X, Y co-ordinates on the RigidBody) where the end point of the joint connects to the other object.
Auto Configure Distance Check this box to automtically detect the distance between the two objects and set it as the distance that the joint keeps between the two objects.
Distance The distance that the spring should attempt to maintain between the two objects. (Can be set manually.)
Damping RatioA joint setting to control spring oscillation. A higher damping ratio means the spring will come to rest faster. More info
See in Glossary
The degree to which you want to suppress spring oscillation: In the range 0 to 1, the higher the value, the less movement.
Frequency The frequency at which the spring oscillates while the objects are approaching the separation distance you want (measured in cycles per second): In the range 0 to 1,000,000 - the higher the value, the stiffer the spring.
Break Force Specify the force level needed to break and so delete the joint. Infinity means it is unbreakable.

Details

(See also Joints 2D: Details and Hints for useful background information on all 2D joints.)

This joint behaves like a spring. Its aim is to keep a linear distance between two points. You set this via the Distance setting. Those two points can be two Rigidbody2D components or a Rigidbody2D component and a fixed position in the world. (Connect to a fixed position in the world by setting Connected Rigidbody to None). The joint aplies a linear force to both rigid bodies. It doesn’t apply torque (an angle force).

The joint uses a simulated spring. You can set the spring’s stiffness and movement:

A stiff, barely moving spring…

  • A high (1,000,000 is the highest) Frequency == a stiff spring.

  • A high (1 is the highest) Damping Ratio == a barely moving spring.

A loose, moving spring…

  • A low Frequency == a loose spring.

  • A low Damping Ratio == a moving spring.

When the spring applies its force between the objects, it tends to overshoot the distance you have set between them, and then rebound repeatedly, giving in a continuous oscillation. The Damping Ratio sets how quickly the objects stop moving. The Frequency sets how quickly the objects oscillate either side of the target distance.

This joint has one constraint:

  • Maintain a zero linear distance between two anchor points on two rigid body objects.

For Example:

You can use this joint to construct physical objects that need to react as if they are connected together using a spring or a connection which allows rotation. Such as:

  • A character who’s body is composed of multiple objects that act as if they are semi-rigid. Use the the Spring JointA joint type that connects two Rigidbody components together but allows the distance between them to change as though they were connected by a spring. More info
    See in Glossary
    to connect the character’s body parts together, allowing them to flex to and from each other. You can specify whether the body parts are held together loosely or tightly.

HINTS:

  • Zero in the Frequency is a special case: It gives the stiffest spring possible.
  • Spring Joint 2D uses a Box 2D spring-joint. Distance Joint 2D also uses the same Box 2D spring-joint but it sets the frequency to zero! Technically, a Spring Joint 2D with a frequency of zero and damping of 1 is identical to a Distance Joint 2D!
Slider Joint 2D
Target Joint 2D