Skip to main content

Physics.Constraint

Class

Constraints body motion in configurable ways, for simulating physical objects such as joints and hinges.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v164

Index

Example

// 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(BodyComponent.getTypeName());
staticBoxBody.dynamic = false;

var hangingBox = script.hangingBox;
var hangingBoxBody = hangingBox.createComponent(BodyComponent.getTypeName());

// 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(ConstraintComponent.getTypeName());

// 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();

Extends

Extended by

Properties

constraintType

readonly constraintType: ConstraintType

The type of constraint that is applied.

Since

Lens Scripting Version 164

Methods

create()

static create(type): Constraint

Create a constraint of the given type, with default settings.

Parameters

ParameterType
typeConstraintType

Returns

Constraint

Since

Lens Scripting Version 164


getTypeName()

static getTypeName(): TypeName<Constraint>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<Constraint>

Since

Lens Scripting Version 164

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

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

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

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

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame