Version: Unity 6.7 Beta (6000.7)
Language : English
Introduction to constraints
Detect constraint events

Add a constraint

To connect two 2D Physics Core objects, add a Physics Constraint component to one of them, and assign the other as the object it connects to.

Note: This documentation is about using Pose, Area, and Constraint components. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.

Follow these steps:

  1. Select a GameObject with a Physics Pose component.

  2. In the Inspector window, select Add Component.

  3. Select Physics 2D (Core), then select a constraint component, for example Physics Constraint Distance.

    Unity connects one end of the constraint to this GameObject, by setting Pose A Source to the Physics Pose component. To connect a different GameObject instead, set Pose A Source to Custom.

  4. Expand the Pose section, then drag the second GameObject you want to connect to the Pose B Target property, or select the picker ().

For the full list of Physics Constraint components and what each one does, refer to Introduction to constraints.

Configure springiness

Note: Some constraints don’t have a spring.

To make the constraint act like a spring, follow these steps:

  1. In the Inspector window, expand the Definition section, then expand Spring.
  2. Enable Enable Spring.
  3. Set Spring Frequency to a value greater than 0. A lower value makes the spring stiffer.
  4. Set Spring Damping to a value greater than 0. A higher value makes the spring settle more quickly.

Add a motor

Note: Some constraints don’t have a motor.

To make the constraint act like a winch that pulls or pushes the connected objects, follow these steps:

  1. In the Inspector window, expand the Definition section, then expand Motor.
  2. Enable Enable Motor.
  3. Set Motor Speed to a value greater than 0 to make the motor push the connected objects apart, or less than 0 to make the motor pull the connected objects together.
  4. Set Max Motor Force or Max Motor Torque to a value greater than 0. These properties set the maximum force that the motor applies to reach the Motor Speed.

Share constraint properties

To share the same properties across multiple constraints, create a definition asset. For more information, refer to Share properties across multiple 2D Physics Core components.

To also allow the shapes on the two connected objects to collide with each other, enable Collide Connected in the Definition section of the constraint component.

Additional resources

Introduction to constraints
Detect constraint events