Lens Scripting API

    Class ConstraintComponent

    Used to apply specific restrictions on how a SceneObject with BodyComponent can move.

    This component allows developers to simulate certain types of mechanical connections or joints between objects.

    Constrain Types guide.

    // Given two objects, with hangingBox below staticBox
    // apply a constraint on hangingBox so that it hangs on the staticBox
    // Try assigning a box object for each input!

    // @input SceneObject staticBox
    // @input SceneObject hangingBox

    // Setup the boxes to have physics
    var staticBox = script.staticBox;
    var staticBoxBody = staticBox.createComponent("Physics.BodyComponent");
    staticBoxBody.dynamic = false;

    var hangingBox = script.hangingBox;
    var hangingBoxBody = hangingBox.createComponent("Physics.BodyComponent");

    // Create a child object that we can set up as our hinge
    var hingeObj = global.scene.createSceneObject("hinge");
    hingeObj.setParent(hangingBox);

    // First we use the child object as a constraint
    var hingeConstraint = hingeObj.createComponent("Physics.ConstraintComponent");

    // Then we set up the constraint as a hinge
    hingeConstraint.debugDrawEnabled = true;
    hingeConstraint.constraint = Physics.Constraint.create(Physics.ConstraintType.Hinge);

    // Attach our hinge to another Physics body
    hingeConstraint.target = staticBoxBody;

    // Position the hinge
    hingeObj.getTransform().setLocalPosition(new vec3(-7.5, 7.5, 0))

    // Tell the system to recalculate the simulation based on the above parameters
    hingeConstraint.reanchorTarget();

    Hierarchy (View Summary, Expand)

    Index

    Constructors

    Properties

    constraint: Constraint

    Dictates constraint type and settings. Note, when setting this field it creates a copy of the constraint, rather than referencing it. So if you intend to modify the constraint after assigning it, you must do so on the component's constraint field, rather than the source constraint object.

    debugDrawEnabled: boolean

    Show the constraint with debug-draw.

    enabled: boolean

    If disabled, the Component will stop enacting its behavior.

    sceneObject: SceneObject

    The scene object this component is on.

    Reference to connected target collider. If null, constraint target is attached to a fixed world transform.

    uniqueIdentifier: string

    Methods

    • Destroys the component.

      Returns void

    • Returns the name of this object's type.

      Returns string

    • Returns true if the object matches or derives from the passed in type.

      Parameters

      • type: string

      Returns boolean

    • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

      Parameters

      Returns boolean

    • The target is attached to the constraint by a fixed local-space matrix, calculated from the difference between the target's and the constraint's world-space transforms. This local-space matrix is generated on-load, or whenever the target is changed. Call this function to explicitly recalculate it for the current world-space transforms.

      Returns void

    MMNEPVFCICPMFPCPTTAAATR