Constraints
Constraints restrict rigidbodies to certain movement patterns. For example, a realistic knee joint can only move along one axis and can't bend forwards.
Constraints can either link two rigidbodies together, or link a single rigidbody to a point in the world. They allow for interaction and dependency among rigidbodies.
There are six types of constraints:
- gears
- sliders
- cones (twist and turn)
- point to point (fixed distance between two colliders)
- six degrees of freedomFor a demonstration of the different constraints, load the PhysicsSample sample project.
Note
To create a constraint, use the Simulation static method :
This links RigidBodyA to the world at its current location.The boolean specifies which coordinate system the limit is applied to (either RigidBodyA or the world).
Note
- In the case of ConstraintTypes.Point2Point, the frame represents a pivot in A. Only the translation vector is considered. is ignored.
- In the case of ConstraintTypes.ConeTwist, is ignored.
- ConstraintTypes.Gear needs two rigidbodies to be created. This function will throw an exception.
This method links to RigidBodyB.
Note
- In the case of ConstraintTypes.Point2Point, the frame represents a pivot in A or B. Only the translation vector is considered. is ignored.
- In the case of ConstraintTypes.Hinge the frame represents pivot in A/B and Axis in A/B. This is because the hinge allows only a limited angle of rotation between the rigidbody and the world in this case.
- In the case of , useReferenceFrameA is ignored.
- In the case of , useReferenceFrameA is ignored. The frame just represents the axis either in A or B; only the translation vector (which should contain the axis) is used.
After you create a constraint, add it to the simulation from a script by calling:
or:
The parameter stops linked bodies colliding with each other.