# PhysicsDistanceJointDefinition

> A joint definition used to specify properties when creating a PhysicsDistanceJoint.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.U2D.Physics](/engine/6000.7/script-reference/unity/u2d/physics.md)
* **Assembly:** UnityEngine.PhysicsCore2DModule
* **Implements:** [IEquatable\<PhysicsDistanceJointDefinition>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct PhysicsDistanceJointDefinition : IEquatable<PhysicsDistanceJointDefinition>
```

## Remarks

Set [\_bodyA](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/bodya.md) and [\_bodyB](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/bodyb.md) to the two bodies you want to connect, then pass the definition into [PhysicsWorld.CreateJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsworld/createjoint.md) to constrain them to a fixed distance apart. For more information about definitions, refer to [PhysicsBodyDefinition](/engine/6000.7/script-reference/unity/u2d/physics/physicsbodydefinition.md).

Additional Resources: [PhysicsJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsjoint.md)

## Examples

```csharp
// Connect two existing bodies with a distance joint set to 2 meters apart.
using UnityEngine;
using Unity.U2D.Physics;

public class CreateDistanceJointDefinitionExample : MonoBehaviour
{
    void Start()
    {
        PhysicsWorld world = PhysicsWorld.defaultWorld;
        PhysicsBody body1 = world.CreateBody();
        PhysicsBody body2 = world.CreateBody();

        PhysicsDistanceJointDefinition jointDefinition = new PhysicsDistanceJointDefinition
        {
            bodyA = body1,
            bodyB = body2,
            autoDistance = false,
            distance = 2f
        };
        PhysicsJoint distanceJoint = world.CreateJoint(jointDefinition);
    }
}
```

## Constructors

| Constructor                                                                                                                                                                       | Description                                                                                                                    |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| [PhysicsDistanceJointDefinition()](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/ctor.md#physicsdistancejointdefinition\(\))                   | Create a default [PhysicsDistanceJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejoint.md) definition. |
| [PhysicsDistanceJointDefinition(System.Boolean)](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/ctor.md#physicsdistancejointdefinition\(bool\)) | Create a default [PhysicsDistanceJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejoint.md) definition. |

## Properties

| Property                                                                                                                 | Description                                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [autoAnchorA](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/autoanchora.md)           | When set, [\_localAnchorA](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/localanchora.md) is recomputed from the bodies' current placement at create so both anchor frames coincide in world space. |
| [autoAnchorB](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/autoanchorb.md)           | When set, [\_localAnchorB](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/localanchorb.md) is recomputed from the bodies' current placement at create so both anchor frames coincide in world space. |
| [autoDistance](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/autodistance.md)         | When set, [\_distance](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/distance.md) is recomputed at create from the world separation of the two anchors.                                             |
| [bodyA](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/bodya.md)                       | The first body the joint constrains.                                                                                                                                                                                                   |
| [bodyB](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/bodyb.md)                       | The second body the joint constrains.                                                                                                                                                                                                  |
| [collideConnected](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/collideconnected.md) | Whether the shapes on the pair of bodies can come into contact.                                                                                                                                                                        |
| [distance](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/distance.md)                 | The desired distance constraint i.e. the rest length of this joint. This has a lower stable limit of just above zero.                                                                                                                  |
| [drawScale](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/drawscale.md)               | Controls the scaling of the joint drawing. Not all joints have scalable elements but those that do will use this scaling.                                                                                                              |
| [enableLimit](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/enablelimit.md)           | Enable/disable the joint limit.                                                                                                                                                                                                        |
| [enableMotor](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/enablemotor.md)           | Enable/Disable the joint motor.                                                                                                                                                                                                        |
| [enableSpring](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/enablespring.md)         | Enable/Disable the distance constraint to behave like a spring. If false then the distance joint will be rigid, overriding the limit and motor.                                                                                        |
| [forceThreshold](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/forcethreshold.md)     | The force threshold beyond which a joint event will be produced.                                                                                                                                                                       |
| [localAnchorA](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/localanchora.md)         | The local anchor frame constraint relative to bodyA's origin.                                                                                                                                                                          |
| [localAnchorB](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/localanchorb.md)         | The local anchor frame constraint relative to bodyB's origin.                                                                                                                                                                          |
| [maxDistanceLimit](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/maxdistancelimit.md) | Maximum length limit of this joint. Must be greater than or equal to the minimum length.                                                                                                                                               |
| [maxMotorForce](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/maxmotorforce.md)       | The maximum force the motor can apply, usually in newtons.                                                                                                                                                                             |
| [minDistanceLimit](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/mindistancelimit.md) | Minimum length limit of this joint. This will be clamped to a lower stable limit.                                                                                                                                                      |
| [motorSpeed](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/motorspeed.md)             | The desired motor speed, usually in meters per second.                                                                                                                                                                                 |
| [springDamping](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/springdamping.md)       | The spring linear damping, non-dimensional. Use 1 for critical damping.                                                                                                                                                                |
| [springFrequency](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/springfrequency.md)   | The spring linear stiffness frequency, in cycles per second.                                                                                                                                                                           |
| [springLowerForce](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/springlowerforce.md) | The lower spring force controls how much tension the spring can sustain.                                                                                                                                                               |
| [springUpperForce](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/springupperforce.md) | The upper spring force controls how much compression the spring can sustain.                                                                                                                                                           |
| [torqueThreshold](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/torquethreshold.md)   | The torque threshold beyond which a joint event will be produced.                                                                                                                                                                      |
| [tuningDamping](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/tuningdamping.md)       | Controls the joint stiffness damping, non-dimensional. Use 1 for critical damping.                                                                                                                                                     |
| [tuningFrequency](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/tuningfrequency.md)   | Controls the joint stiffness frequency, in cycles per second.                                                                                                                                                                          |
| [worldDrawing](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/worlddrawing.md)         | Controls whether this joint is automatically drawn when the world is drawn.                                                                                                                                                            |

## Static Properties

| Property                                                                                                                   | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [defaultDefinition](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejointdefinition/defaultdefinition.md) | Get a default [PhysicsDistanceJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsdistancejoint.md) definition. |
