Intersection filter settings. Unifies settings for world probes and collider overlap tests. See also: ColliderComponent, Physics.

// Given an object with a BodyComponent
// If the object intersects with the ray described
// by rayStart and rayEnd,
// AND the object is Dynamic (not Static or Intangible)
// print a message

var rayStart = new vec3(0.0, -100.0, 0.0);
var rayEnd = new vec3(0.0, 100.0, 0.0);

// Create a probe to raycast through all worlds.
var globalProbe = Physics.createGlobalProbe();

// Set filter settings on it.
probe.filter.includeStatic = false;
probe.filter.includeDynamic = true;
probe.filter.includeIntangible = false;

globalProbe.rayCast(rayStart, rayEnd, function (hit) {
if (hit) {
print("Raycast hit: " + hit.collider.getSceneObject().name);
}
});
// 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);
});
interface Filter {
    includeDynamic: boolean;
    includeIntangible: boolean;
    includeStatic: boolean;
    onlyColliders: ColliderComponent[];
    onlyLayers: LayerSet;
    skipColliders: ColliderComponent[];
    skipLayers: LayerSet;
    getTypeName(): string;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
}

Hierarchy (view full)

Properties

includeDynamic: boolean

Include dynamic objects in intersection tests.

includeIntangible: boolean

Include intangible objects in intersection tests.

includeStatic: boolean

Include static objects in intersection tests.

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

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

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.

Methods

  • 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