Used to apply a constraint to an object.

// 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();
interface ConstraintComponent {
    constraint: Constraint;
    debugDrawEnabled: boolean;
    enabled: boolean;
    sceneObject: SceneObject;
    target: ColliderComponent;
    uniqueIdentifier: string;
    destroy(): void;
    getSceneObject(): SceneObject;
    getTransform(): Transform;
    getTypeName(): string;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
    reanchorTarget(): void;
}

Hierarchy (view full)

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

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