Constraints

AdvancedProgrammer

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:

  • hinges
  • 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.

Create a constraint

Note

Currently, you can only use constraints from scripts.

To create a constraint, use the Simulation static method CreateConstraint:

  1. CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA);

This links RigidBodyA to the world at its current location.The boolean useReferenceFrameA specifies which coordinate system the limit is applied to (either RigidBodyA or the world).

Note
  1. CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA)

This method links RigidBodyA to RigidBodyB.

Note

The boolean useReferenceFrameA determines which coordinate system (RigidBodyA or RigidBodyB) the limits are applied to.

Add constraints to the simulation

After you create a constraint, add it to the simulation from a script by calling:

  1. this.GetSimulation().AddConstraint(constraint);

or:

  1. var disableCollisionsBetweenLinkedBodies = true;
  2. this.GetSimulation().AddConstraint(constraint, disableCollisionsBetweenLinkedBodies);

The parameter disableCollisionsBetweenLinkedBodies stops linked bodies colliding with each other.

Likewise, to remove a constraint from the simulation, use:

  1. this.GetSimulation().RemoveConstraint(constraint);

See also