Learn what a Physics Constraint component does, and understand motors and springs.
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.
A Physics Constraint component connects two objects. Most constraints force two objects to stay at a fixed distance, or rotate them around a point.
For example, you can create a fixed constraint that welds two objects together, or a distance constraint that keeps them a set distance apart. Use constraints to simulate real-world mechanical behaviours like a spring or a hinge.
Most constraints allow you to set the anchor points on the objects they connect, and limits on the force and torque they apply.
2D Physics Core provides seven types of Physics Constraint component.
| Constraint type | Description |
|---|---|
| Physics Constraint Distance | Tries to keep two connected objects a certain distance apart. |
| Physics Constraint Fixed | Tries to keep the two connected objects at the same position and rotation. |
| Physics Constraint Hinge | Places two objects at the same location, and allows the second object to rotate while connected to the first. |
| Physics Constraint Ignore | Prevents collisions between two objects, and otherwise doesn’t affect the objects or their movement. |
| Physics Constraint Relative | Moves and rotates objects opposite to each other. |
| Physics Constraint Slider | Allows one object to restrict a second object so it can only slide along one axis. The rotation of the first object defines the axis. |
| Physics Constraint Wheel | Pins two objects together, for example a suspension object and a wheel. You can then rotate the second object with a motor so it moves along the ground. |
Most constraints let you configure the following in the Definition section of their Inspector window. Each one is a collapsible group that’s closed by default.
For more information, refer to Add a constraint.