PhysicsDistanceJointDefinition
A joint definition used to specify properties when creating a PhysicsDistanceJoint.
Read time 3 minutesLast updated 13 days ago
Definition
- Type: Struct
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
- Implements: IEquatable<PhysicsDistanceJointDefinition>
public struct PhysicsDistanceJointDefinition : IEquatable<PhysicsDistanceJointDefinition>
Remarks
Set _bodyA and _bodyB to the two bodies you want to connect, then pass the definition into PhysicsWorld.CreateJoint to constrain them to a fixed distance apart. For more information about definitions, refer to PhysicsBodyDefinition.
Additional Resources: PhysicsJoint
Examples
// 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() | Create a default PhysicsDistanceJoint definition. |
| PhysicsDistanceJointDefinition(System.Boolean) | Create a default PhysicsDistanceJoint definition. |
Properties
Property | Description |
|---|---|
| autoAnchorA | When set, _localAnchorA is recomputed from the bodies' current placement at create so both anchor frames coincide in world space. |
| autoAnchorB | When set, _localAnchorB is recomputed from the bodies' current placement at create so both anchor frames coincide in world space. |
| autoDistance | When set, _distance is recomputed at create from the world separation of the two anchors. |
| bodyA | The first body the joint constrains. |
| bodyB | The second body the joint constrains. |
| collideConnected | Whether the shapes on the pair of bodies can come into contact. |
| distance | The desired distance constraint i.e. the rest length of this joint. This has a lower stable limit of just above zero. |
| drawScale | Controls the scaling of the joint drawing. Not all joints have scalable elements but those that do will use this scaling. |
| enableLimit | Enable/disable the joint limit. |
| enableMotor | Enable/Disable the joint motor. |
| enableSpring | 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 | The force threshold beyond which a joint event will be produced. |
| localAnchorA | The local anchor frame constraint relative to bodyA's origin. |
| localAnchorB | The local anchor frame constraint relative to bodyB's origin. |
| maxDistanceLimit | Maximum length limit of this joint. Must be greater than or equal to the minimum length. |
| maxMotorForce | The maximum force the motor can apply, usually in newtons. |
| minDistanceLimit | Minimum length limit of this joint. This will be clamped to a lower stable limit. |
| motorSpeed | The desired motor speed, usually in meters per second. |
| springDamping | The spring linear damping, non-dimensional. Use 1 for critical damping. |
| springFrequency | The spring linear stiffness frequency, in cycles per second. |
| springLowerForce | The lower spring force controls how much tension the spring can sustain. |
| springUpperForce | The upper spring force controls how much compression the spring can sustain. |
| torqueThreshold | The torque threshold beyond which a joint event will be produced. |
| tuningDamping | Controls the joint stiffness damping, non-dimensional. Use 1 for critical damping. |
| tuningFrequency | Controls the joint stiffness frequency, in cycles per second. |
| worldDrawing | Controls whether this joint is automatically drawn when the world is drawn. |
Static Properties
Property | Description |
|---|---|
| defaultDefinition | Get a default PhysicsDistanceJoint definition. |