Skip to main content

Physics.Filter

Class

Script interface for applying collision filtering to colliders and ray/shape-casts.

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

Index

Example

// Create a new filter and adjust its settings.
var filter = Physics.Filter.create();
filter.skipLayers = LayerSet.fromNumber(101);
filter.onlyColliders = [script.myCollider1, script.myCollider2];

// Assign the filter as default for the root world so it affects all colliders.
var settings = Physics.getRootWorldSettings();
settings.defaultFilter = filter;

// Perform a ray cast using the filter.
var probe = Physics.createGlobalProbe();
probe.filter = filter;
probe.rayCast(new vec3(0, 100, 0), new vec3(0, -100, 0), function (hit) {
print(hit);
});

// Use the filter for collider overlap test.
script.myCollider3.overlapFilter = filter;
script.myCollider3.onOverlapEnter.add(function (e) {
print("OverlapEnter(" + e.overlap.id + "): " + e.overlap.collider);
});

Extends

Properties

includeBackfaces

includeBackfaces: boolean

Include backface hits in raycast tests. When disabled, rays only hit front-facing surfaces. This setting only affects raycasts, not shapecasts.

Default Value

false

Example

var probe = Physics.createGlobalProbe();
probe.filter.includeBackfaces = true;

var rayStart = new vec3(0, 0, -10);
var rayEnd = new vec3(0, 0, 10);
var rayVec = rayEnd.sub(rayStart);

probe.rayCastAll(rayStart, rayEnd, function (hits) {
for (var i = 0; i < hits.length; i++) {
var isBackface = hits[i].normal.dot(rayVec) > 0;
}
});

includeDynamic

includeDynamic: boolean

Include dynamic objects in intersection tests.

Default Value

true

includeIntangible

includeIntangible: boolean

Include intangible objects in intersection tests.

Default Value

false

includeStatic

includeStatic: boolean

Include static objects in intersection tests.

Default Value

true

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


onlyColliders

onlyColliders: ColliderComponent[]

If non-empty, only perform collision with these colliders. In other words: the set of colliders to include when performing collision tests, excluding all others. If empty, this setting is disabled (effectively including all colliders, minus skipColliders).

Default Value

[]

onlyLayers

onlyLayers: LayerSet

If non-empty, only perform collision with colliders in these layers. In other words: the set of layers to include when performing collision tests, excluding all others. If empty, this setting is disabled (effectively including all layers, minus skipLayers).


skipColliders

skipColliders: ColliderComponent[]

Skip collision with these colliders. In other words: the set of colliders to exclude when performing collision tests. This takes precedence over onlyColliders, so a collider that is in both is skipped.

Default Value

[]

skipLayers

skipLayers: LayerSet

Skip collision with colliders in these layers. In other words: the set of layers to exclude when performing collision tests. This takes precedence over onlyLayers, so a layer that is in both is skipped.


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

create()

static create(): Filter

Create an instance with default settings.

Returns

Filter


getTypeName()

static getTypeName(): TypeName<Filter>

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

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

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

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

Asset.isSame