Skip to main content

ColliderComponent

Class

Used to define the physical boundaries of an object, allowing it to interact with other objects in Physics, Cloth or Hair simulation.

  • 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 v152

Index

Remarks

Provides a way for SceneObjects to detect and respond to collisions. Useful for detecting when objects overlap or contact each other, which can then be used to trigger events or effects within the Lens experience.

Example

// Add a callback for onCollisionEnter on this collider

// @input Physics.ColliderComponent collider

script.collider.onCollisionEnter.add(function(eventArgs) {
var collision = eventArgs.collision;
print("CollisionEnter(" + collision.id + "): contacts=" + collision.contactCount + " ---> " + collision.collider.getSceneObject().name);
});

Extends

Extended by

Properties

angularVelocity

angularVelocity: vec3

Angular velocity, expressed as an axis of rotation scaled by angular speed (radians/s).

Since

Lens Scripting Version 164

Default Value

(0, 0, 0)

debugDrawEnabled

debugDrawEnabled: boolean

Toggle collider wire rendering for visualizing collider geometry shape and where it is placed.

Since

Lens Scripting Version 152

Default Value

false

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

Component.enabled


excludeFromParentCompounding

excludeFromParentCompounding: boolean

If enabled, this collider is never merged into an ancestor's compound shape; it always becomes its own top-level collider simulated with its own settings.

Remarks

This toggle is independent of ColliderComponent#forceCompound: it only controls whether this collider joins an ancestor's compound, and it does not change whether this collider aggregates its own descendants. That remains governed by ColliderComponent#forceCompound or being a dynamic body. Splitting out of a compound does not suppress collisions with the former compound. Whether the two collide is governed by the normal collision-filtering rules, subject to their SceneObject#layer, ColliderComponent#filter, and ColliderComponent#intangible settings.

Since

Lens Scripting Version 378

Default Value

false

Example

// Keep an oversized interaction-only trigger out of its parent body's compound shape
// @input Physics.ColliderComponent triggerCollider
script.triggerCollider.excludeFromParentCompounding = true;
script.triggerCollider.intangible = true;

filter

filter: Filter

Collision filter to use for this collider.

Since

Lens Scripting Version 183

Default Value

null

fitVisual

fitVisual: boolean

If enabled, the collider shape extends to fit the visual mesh, if any. Only applicable for Box and Sphere shapes.

Since

Lens Scripting Version 164

Default Value

true

forceCompound

forceCompound: boolean

Nested collider/body components may be merged into compound shapes. By default, this occurs only for dynamic bodies and not for static colliders. If forceCompound is set, this occurs for static colliders as well.

Since

Lens Scripting Version 169

Default Value

false

intangible

intangible: boolean

If enabled, the collider doesn't interact with the world but may still be detected with ray casts and intersection events.

Since

Lens Scripting Version 164

Default Value

false

isBeingDestroyed

readonly isBeingDestroyed: 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

Component.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

Inherited from

Component.isEnabledInHierarchy


matter

matter: Matter

The matter used by the collider to define its physical substance, such as friction and bounciness.

Since

Lens Scripting Version 169

Default Value

null

onCollisionEnter

readonly onCollisionEnter: event1<CollisionEnterEventArgs, void>

Signals when objects initially collide.

Since

Lens Scripting Version 152


onCollisionExit

readonly onCollisionExit: event1<CollisionExitEventArgs, void>

Signals when objects stop colliding.

Since

Lens Scripting Version 152


onCollisionStay

readonly onCollisionStay: event1<CollisionStayEventArgs, void>

Signals every frame while objects continue to collide.

Since

Lens Scripting Version 152


onOverlapEnter

readonly onOverlapEnter: event1<OverlapEnterEventArgs, void>

Signals when colliders first overlap.

Since

Lens Scripting Version 152


onOverlapExit

readonly onOverlapExit: event1<OverlapExitEventArgs, void>

Signals when colliders stop overlapping.

Since

Lens Scripting Version 152


onOverlapStay

readonly onOverlapStay: event1<OverlapStayEventArgs, void>

Signals every frame while colliders continue to overlap.

Since

Lens Scripting Version 152


overlapFilter

overlapFilter: Filter

Collision filter used for overlap events.

Since

Lens Scripting Version 164

Default Value

null

rotateSmoothFactor

rotateSmoothFactor: number

Smoothing spring factor, for rotation.

Since

Lens Scripting Version 169

Default Value

30

sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

Component.sceneObject


shape

shape: Shape

The Shape object used for collision.

Since

Lens Scripting Version 157

Default Value

null

smooth

smooth: boolean

Smooth transform changes using a dampened spring. Useful to reduce motion noise. This only applies to the simulation and changes from outside the simulation. The SceneObject's transform is not affected. It has no effect for dynamic bodies.

Since

Lens Scripting Version 169

Default Value

false

translateSmoothFactor

translateSmoothFactor: number

Smoothing spring factor, for translation. This controls the restitution strength of the spring, so low values are smoother but lag more.

Since

Lens Scripting Version 169

Default Value

30

uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Component.uniqueIdentifier


velocity

velocity: vec3

Linear velocity (cm/s).

Since

Lens Scripting Version 164

Default Value

(0, 0, 0)

worldSettings

worldSettings: WorldSettingsAsset

The WorldSettingsAsset used by the collider to define the physics simulation settings.

Since

Lens Scripting Version 169

Default Value

null

Methods

clearMotion()

clearMotion(): void

Clears all velocities and forces on a collider.

Returns

void

Since

Lens Scripting Version 164


destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

Component.destroy


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

Component.getSceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

Component.getTransform


getTypeName()

static getTypeName(): TypeName<ColliderComponent>

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<ColliderComponent>

Since

Lens Scripting Version 152

Overrides

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Component.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

Component.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

Component.isSame

See also