ConstraintComponent
ClassUsed to apply specific restrictions on how a SceneObject with BodyComponent can move.
- Available on all platforms
Since Lens Scripting v164
Index
Properties
Methods
Remarks
This component allows developers to simulate certain types of mechanical connections or joints between objects.
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
Properties
constraint
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.
Since
Lens Scripting Version 164
Default Value
null
debugDrawEnabled
debugDrawEnabled:
boolean
Show the constraint with debug-draw.
Since
Lens Scripting Version 164
Default Value
false
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
Inherited from
isBeingDestroyed
readonlyisBeingDestroyed:boolean
Returns true if this Component is currently being destroyed. Becomes true as soon as
destruction begins via Component#destroy or destruction of its owning SceneObject,
before any OnDestroyEvent callbacks fire.
Since
Lens Scripting Version 364
Example
if (!script.isBeingDestroyed) {
// Component is still fully alive
}
Inherited from
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
Inherited from
Component.isEnabledInHierarchy
linkedBodyCollisionEnabled
linkedBodyCollisionEnabled:
boolean
Controls whether the two bodies connected by this constraint are allowed to collide with each other. When enabled, connected bodies can collide normally. When disabled, collision detection between them is suppressed. Disable for doors and joints to avoid jitter; keep enabled for ragdolls where adjacent limbs must collide to prevent interpenetration.
Since
Lens Scripting Version 359
Default Value
true
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
target
target:
ColliderComponent
Reference to connected target collider. If null, constraint target is attached to a fixed world transform.
Since
Lens Scripting Version 164
Default Value
null
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<ConstraintComponent>
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<ConstraintComponent>
Since
Lens Scripting Version 164
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
reanchorTarget()
reanchorTarget():
void
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
Since
Lens Scripting Version 164
See also
Constrain Types guide.