Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PhysicsDistanceJointDefinition

A joint definition used to specify properties when creating a PhysicsDistanceJoint.
Read time 3 minutesLast updated 13 days ago

Definition

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

autoAnchorAWhen set, _localAnchorA is recomputed from the bodies' current placement at create so both anchor frames coincide in world space.
autoAnchorBWhen set, _localAnchorB is recomputed from the bodies' current placement at create so both anchor frames coincide in world space.
autoDistanceWhen set, _distance is recomputed at create from the world separation of the two anchors.
bodyAThe first body the joint constrains.
bodyBThe second body the joint constrains.
collideConnectedWhether the shapes on the pair of bodies can come into contact.
distanceThe desired distance constraint i.e. the rest length of this joint. This has a lower stable limit of just above zero.
drawScaleControls the scaling of the joint drawing. Not all joints have scalable elements but those that do will use this scaling.
enableLimitEnable/disable the joint limit.
enableMotorEnable/Disable the joint motor.
enableSpringEnable/Disable the distance constraint to behave like a spring. If false then the distance joint will be rigid, overriding the limit and motor.
forceThresholdThe force threshold beyond which a joint event will be produced.
localAnchorAThe local anchor frame constraint relative to bodyA's origin.
localAnchorBThe local anchor frame constraint relative to bodyB's origin.
maxDistanceLimitMaximum length limit of this joint. Must be greater than or equal to the minimum length.
maxMotorForceThe maximum force the motor can apply, usually in newtons.
minDistanceLimitMinimum length limit of this joint. This will be clamped to a lower stable limit.
motorSpeedThe desired motor speed, usually in meters per second.
springDampingThe spring linear damping, non-dimensional. Use 1 for critical damping.
springFrequencyThe spring linear stiffness frequency, in cycles per second.
springLowerForceThe lower spring force controls how much tension the spring can sustain.
springUpperForceThe upper spring force controls how much compression the spring can sustain.
torqueThresholdThe torque threshold beyond which a joint event will be produced.
tuningDampingControls the joint stiffness damping, non-dimensional. Use 1 for critical damping.
tuningFrequencyControls the joint stiffness frequency, in cycles per second.
worldDrawingControls whether this joint is automatically drawn when the world is drawn.

Static Properties

Property

Description

defaultDefinitionGet a default PhysicsDistanceJoint definition.